From e56be341482e5a2e620c08dec3c0595a8fdb976a Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 4 Dec 2021 18:55:59 -0500 Subject: [PATCH] LibJS: Implement Date's TimeClip AO --- Userland/Libraries/LibJS/Runtime/Date.cpp | 15 +++++++++++++++ Userland/Libraries/LibJS/Runtime/Date.h | 1 + 2 files changed, 16 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 60e31f1359..9d6337caa3 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -389,4 +389,19 @@ Value make_date(Value day, Value time) return tv; } +// 21.4.1.14 TimeClip ( time ), https://tc39.es/ecma262/#sec-timeclip +Value time_clip(GlobalObject& global_object, Value time) +{ + // 1. If time is not finite, return NaN. + if (!time.is_finite_number()) + return js_nan(); + + // 2. If abs(ℝ(time)) > 8.64 × 10^15, return NaN. + if (fabs(time.as_double()) > 8.64E15) + return js_nan(); + + // 3. Return 𝔽(! ToIntegerOrInfinity(time)). + return Value(MUST(time.to_integer_or_infinity(global_object))); +} + } diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h index 3073969a2a..f2bb4b7a5a 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.h +++ b/Userland/Libraries/LibJS/Runtime/Date.h @@ -102,5 +102,6 @@ double day(double); Value make_time(GlobalObject& global_object, Value hour, Value min, Value sec, Value ms); Value make_day(GlobalObject& global_object, Value year, Value month, Value date); Value make_date(Value day, Value time); +Value time_clip(GlobalObject& global_object, Value time); }