Skip to content

Commit

Permalink
Merge pull request #5798 from kenjis/fix-timer
Browse files Browse the repository at this point in the history
fix: Timer::getElapsedTime() returns incorrect value
  • Loading branch information
samsonasik authored Mar 13, 2022
2 parents d40f986 + 3c706a5 commit c8dbb73
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions system/Debug/Timer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function stop(string $name)
* @param string $name The name of the timer.
* @param int $decimals Number of decimal places.
*
* @return float|null Returns null if timer exists by that name.
* @return float|null Returns null if timer does not exist by that name.
* Returns a float representing the number of
* seconds elapsed while that timer was running.
*/
Expand All @@ -96,7 +96,7 @@ public function getElapsedTime(string $name, int $decimals = 4)
$timer['end'] = microtime(true);
}

return (float) number_format($timer['end'] - $timer['start'], $decimals);
return (float) number_format($timer['end'] - $timer['start'], $decimals, '.', '');
}

/**
Expand Down
4 changes: 2 additions & 2 deletions tests/system/Debug/TimerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public function testThrowsExceptionStoppingNonTimer()
public function testLongExecutionTime()
{
$timer = new Timer();
$timer->start('longjohn', strtotime('-11 minutes'));
$this->assertCloseEnough(11 * 60, $timer->getElapsedTime('longjohn'));
$timer->start('longjohn', strtotime('-110 minutes'));
$this->assertCloseEnough(110 * 60, $timer->getElapsedTime('longjohn'));
}

public function testLongExecutionTimeThroughCommonFunc()
Expand Down

0 comments on commit c8dbb73

Please sign in to comment.