summaryrefslogtreecommitdiff
path: root/Userland/Libraries
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2021-12-04 18:55:59 -0500
committerLinus Groh <mail@linusgroh.de>2021-12-08 11:29:36 +0000
commite56be341482e5a2e620c08dec3c0595a8fdb976a (patch)
treef645994949e68fa13da9de0f44695440a805fcc8 /Userland/Libraries
parentb76e44f66f2e8bbb72ff42ea26fb751e7087e74e (diff)
downloadserenity-e56be341482e5a2e620c08dec3c0595a8fdb976a.zip
LibJS: Implement Date's TimeClip AO
Diffstat (limited to 'Userland/Libraries')
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp15
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.h1
2 files changed, 16 insertions, 0 deletions
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);
}