Skip to content
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
2 changes: 1 addition & 1 deletion runtime-light/stdlib/time/time-functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<chrono::seconds>(time_since_epoch).count()};
const auto nanoseconds{duration_cast<chrono::nanoseconds>(time_since_epoch).count() % 1'000'000'000};

Expand Down
10 changes: 10 additions & 0 deletions tests/phpt/func_specializations/microtime.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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);
Expand Down
Loading