diff --git a/Tests/test.php b/Tests/test.php index 705887e..26574fa 100644 --- a/Tests/test.php +++ b/Tests/test.php @@ -10,19 +10,25 @@ $timer->start(); sleep(3); $timer->step('sleep 1'); -echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL; -echo $timer->getLastStepDuration() . PHP_EOL; +echo 'sleep 1' . PHP_EOL; +echo "\t" . $timer->getLastStepRelativeDuration() . PHP_EOL; +echo "\t" . $timer->getLastStepDuration() . PHP_EOL; sleep(2); $timer->step('sleep 2'); -echo $timer->getLastStepRelativeDuration()->toUserString() . PHP_EOL; -echo $timer->getLastStepDuration() . PHP_EOL; -$timer->stop(); +echo 'sleep 2' . PHP_EOL; +echo "\t" . $timer->getLastStepRelativeDuration() . PHP_EOL; +echo "\t" . $timer->getLastStepDuration() . PHP_EOL; + +sleep(3); -$final = $timer->getDuration(); -echo $timer->getRelativeDuration()->toUserString() . PHP_EOL; -echo $timer->getRelativeDuration() . PHP_EOL; +$timer->step('sleep 3'); +echo 'sleep 3' . PHP_EOL; +echo "\t" . $timer->getLastStepRelativeDuration() . PHP_EOL; +echo "\t" . $timer->getLastStepDuration() . PHP_EOL; -echo $timer->getDuration()->toUserString() . PHP_EOL; -echo $timer->getDuration() . PHP_EOL; \ No newline at end of file +$timer->stop(); +echo 'STOP' . PHP_EOL; +echo "\t" . $timer->getRelativeDuration() . PHP_EOL; +echo "\t" . $timer->getDuration() . PHP_EOL; \ No newline at end of file diff --git a/src/ExecutionTimer/Duration.php b/src/ExecutionTimer/Duration.php index 2667c51..a60a060 100644 --- a/src/ExecutionTimer/Duration.php +++ b/src/ExecutionTimer/Duration.php @@ -29,11 +29,10 @@ class Duration { */ public function __toString () { return $this->getDays()->asRelativeWhole() . ' ' - . $this->getHours()->asRelativeWhole() . ':' - . $this->getMinutes()->asRelativeWhole() . ':' - . $this->getSeconds()->asRelativeWhole() . '.' - . $this->getMilliseconds()->asRelativeWhole() - . $this->getMicroseconds()->asRelativeWhole(); + . str_pad($this->getHours()->asRelativeWhole(), mb_strlen($this->getHours()->getUnitMax()), '0', STR_PAD_LEFT) . ':' + . str_pad($this->getMinutes()->asRelativeWhole(), mb_strlen($this->getMinutes()->getUnitMax()), '0', STR_PAD_LEFT) . ':' + . str_pad($this->getSeconds()->asRelativeWhole(), mb_strlen($this->getSeconds()->getUnitMax()), '0', STR_PAD_LEFT) . '.' + . str_pad($this->getMilliseconds()->asRelativeWhole(), mb_strlen($this->getMilliseconds()->getUnitMax()), '0', STR_PAD_LEFT); } /** * Convert duration to user friendly string diff --git a/src/ExecutionTimer/DurationUnit.php b/src/ExecutionTimer/DurationUnit.php index 6ee8119..5574e74 100644 --- a/src/ExecutionTimer/DurationUnit.php +++ b/src/ExecutionTimer/DurationUnit.php @@ -47,6 +47,14 @@ class DurationUnit { $this->unit_max = $units_max[$unit]; } + /** + * The time unit + * + * @return int The maximum value of time unit + */ + public function getUnit () { + return $this->unit; + } /** * The maximum value of time unit * @@ -55,8 +63,8 @@ class DurationUnit { * * @return int The maximum value of time unit */ - public function getUnit () { - return $this->unit; + public function getUnitMax () { + return $this->unit_max; } /**