diff --git a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp index a37c39383b..27d4ac9f97 100644 --- a/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp +++ b/Userland/Libraries/LibJS/Runtime/Temporal/Now.cpp @@ -4,6 +4,7 @@ * SPDX-License-Identifier: BSD-2-Clause */ +#include #include #include #include @@ -15,7 +16,6 @@ #include #include #include -#include namespace JS::Temporal { @@ -161,20 +161,12 @@ TimeZone* system_time_zone(GlobalObject& global_object) BigInt* system_utc_epoch_nanoseconds(GlobalObject& global_object) { // 1. Let ns be the approximate current UTC date and time, in nanoseconds since the epoch. - struct timespec now; - clock_gettime(CLOCK_REALTIME, &now); - Checked ns_timestamp; - ns_timestamp += now.tv_sec; - ns_timestamp *= 1'000'000'000; - ns_timestamp += now.tv_nsec; - if (ns_timestamp.has_overflow()) { - // TODO: Deal with this before 2262-04-21T00:47:16Z. - VERIFY_NOT_REACHED(); - } - auto ns = Crypto::SignedBigInteger::create_from(ns_timestamp.value()); + auto now = Time::now_realtime().to_nanoseconds(); + auto ns = Crypto::SignedBigInteger::create_from(now); // 2. Set ns to the result of clamping ns between −8.64 × 10^21 and 8.64 × 10^21. - // Uhh, these don't even fit in an i64... ¯\_(ツ)_/¯ + // NOTE: Time::to_nanoseconds() already clamps between −(2^63) and 2^63 − 1, the range of an i64, + // if an overflow occurs during seconds -> nanoseconds conversion. // 3. Return ℤ(ns). return js_bigint(global_object.heap(), move(ns));