for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
declare(strict_types=1);
namespace loophp\nanobench\Time;
use Exception;
abstract class AbstractTime implements TimeInterface
{
protected string $unit;
protected function convertTo(float $time, string $unit): float
// Convert to seconds.
switch ($this->unit) {
case TimeUnit::NANOSECOND:
$time = $time / 10 ** 9;
break;
case TimeUnit::MICROSECOND:
$time = $time / 10 ** 6;
case TimeUnit::MILLISECOND:
$time = $time / 10 ** 3;
case TimeUnit::SECOND:
$time = $time;
case TimeUnit::MINUTE:
$time = $time * 60;
case TimeUnit::HOUR:
$time = $time * 60 * 60;
case TimeUnit::DAY:
$time = $time * 60 * 60 * 24;
case TimeUnit::WEEK:
$time = $time * 60 * 60 * 24 * 7;
}
switch ($unit) {
return $time * 10 ** 9;
return $time * 10 ** 6;
return $time * 10 ** 3;
return $time;
return $time / 60;
return $time / (60 * 60);
return $time / (60 * 60 * 24);
return $time / (60 * 60 * 24 * 7);
throw new Exception('Unable to convert.');