Skip to content

Commit

Permalink
Different approach for 32-bit support
Browse files Browse the repository at this point in the history
Prior version made time run backwards… oops.
  • Loading branch information
trowski committed May 31, 2019
1 parent 1541424 commit 5316e74
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions lib/Internal/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,24 @@ function createTypeError(array $expected, $given): \TypeError
*/
function getCurrentTime(): int
{
static $startTime;

if (\PHP_VERSION_ID >= 70300) {
list($seconds, $nanoseconds) = \hrtime(false);
$time = (int) ($seconds * 1000 + $nanoseconds / 1000000);
$now = $seconds * 1000 + $nanoseconds / 1000000;
} else {
$time = (int) (\microtime(true) * 1000);
$now = \microtime(true) * 1000;
}

$time = (int) $now;

if ($time < 0) {
if ($startTime === null) {
$startTime = $now;
}

$time = (int) ($now - $startTime);
}

return $time < 0 ? -$time : $time;
return $time;
}

0 comments on commit 5316e74

Please sign in to comment.