1
0
mirror of https://github.com/danog/amp.git synced 2024-11-26 20:15:00 +01:00

Different approach for 32-bit support

Prior version made time run backwards… oops.
This commit is contained in:
Aaron Piotrowski 2019-05-31 12:48:03 -05:00
parent 154142464a
commit 5316e741b7
No known key found for this signature in database
GPG Key ID: ADD1EF783EDE9EEB

View File

@ -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;
}
return $time < 0 ? -$time : $time;
$time = (int) $now;
if ($time < 0) {
if ($startTime === null) {
$startTime = $now;
}
$time = (int) ($now - $startTime);
}
return $time;
}