Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Timer::getElapsedTime() returns incorrect value #5798

Merged
merged 2 commits into from
Mar 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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