From d6dee179704bbc68dfe03707f92f73d8ecea75ee Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 27 May 2026 12:46:37 +0300 Subject: [PATCH 1/2] fix f$_microtime_string function --- runtime-light/stdlib/time/time-functions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/runtime-light/stdlib/time/time-functions.h b/runtime-light/stdlib/time/time-functions.h index 607dd0e7f6..ac52237ec1 100644 --- a/runtime-light/stdlib/time/time-functions.h +++ b/runtime-light/stdlib/time/time-functions.h @@ -47,7 +47,7 @@ inline mixed f$hrtime(bool as_number = false) noexcept { inline string f$_microtime_string() noexcept { namespace chrono = std::chrono; - const auto time_since_epoch{chrono::high_resolution_clock::now().time_since_epoch()}; + const auto time_since_epoch{chrono::system_clock::now().time_since_epoch()}; const auto seconds{duration_cast(time_since_epoch).count()}; const auto nanoseconds{duration_cast(time_since_epoch).count() % 1'000'000'000}; From df7fa8ee0e6013636e62762be69e0d8be1268725 Mon Sep 17 00:00:00 2001 From: Karim Shamazov Date: Wed, 27 May 2026 13:31:31 +0300 Subject: [PATCH 2/2] test --- tests/phpt/func_specializations/microtime.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/tests/phpt/func_specializations/microtime.php b/tests/phpt/func_specializations/microtime.php index c1dd0707d0..7b0f706788 100644 --- a/tests/phpt/func_specializations/microtime.php +++ b/tests/phpt/func_specializations/microtime.php @@ -8,6 +8,14 @@ function ensure_string(string $x) {} const MICROTIME_AS_FLOAT = true; const MICROTIME_AS_STRING = false; +const SECONDS_IN_MINUTE = 60; +const SECONDS_IN_HOUR = 60 * SECONDS_IN_MINUTE; +const SECONDS_IN_DAY = 24 * SECONDS_IN_HOUR; +const SECONDS_IN_WEEK = 7 * SECONDS_IN_DAY; + +// Sun Jan 04 1970 00:00:00 GMT+0000 +const SOME_SUNDAY_MIDNIGHT_TS = SECONDS_IN_DAY * 3; + function test() { ensure_float(microtime(true)); ensure_float(microtime(MICROTIME_AS_FLOAT)); @@ -19,6 +27,8 @@ function test() { ensure_float($float_time); $string_time = microtime(); + list($microsec, $sec) = explode(' ', $string_time); + var_dump((int)(($sec - SOME_SUNDAY_MIDNIGHT_TS) / SECONDS_IN_WEEK)); ensure_string($string_time); $string_time = microtime(false); ensure_string($string_time);