LibJS: Use Temporal for the Date constructor and Date.now()

This commit is contained in:
Timothy Flynn 2024-11-26 10:51:11 -05:00 committed by Tim Flynn
commit 8e8c133db5
Notes: github-actions[bot] 2024-11-26 21:57:43 +00:00
3 changed files with 26 additions and 14 deletions

View file

@ -119,6 +119,19 @@ JS_DEFINE_NATIVE_FUNCTION(Now::plain_time_iso)
return MUST(create_temporal_time(vm, iso_date_time.time));
}
// 2.3.2 SystemUTCEpochMilliseconds ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemutcepochmilliseconds
double system_utc_epoch_milliseconds(VM& vm)
{
// 1. Let global be GetGlobalObject().
auto const& global = vm.get_global_object();
// 2. Let nowNs be HostSystemUTCEpochNanoseconds(global).
auto now_ns = vm.host_system_utc_epoch_nanoseconds(global);
// 3. Return 𝔽(floor(nowNs / 10**6)).
return big_floor(now_ns, NANOSECONDS_PER_MILLISECOND).to_double();
}
// 2.3.3 SystemUTCEpochNanoseconds ( ), https://tc39.es/proposal-temporal/#sec-temporal-systemutcepochnanoseconds
Crypto::SignedBigInteger system_utc_epoch_nanoseconds(VM& vm)
{

View file

@ -32,6 +32,7 @@ private:
JS_DECLARE_NATIVE_FUNCTION(plain_time_iso);
};
double system_utc_epoch_milliseconds(VM&);
Crypto::SignedBigInteger system_utc_epoch_nanoseconds(VM&);
ThrowCompletionOr<ISODateTime> system_date_time(VM&, Value temporal_time_zone_like);