diff options
author | Timothy Flynn <trflynn89@pm.me> | 2022-01-14 13:10:07 -0500 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-01-15 20:13:48 +0100 |
commit | d93713b8744c025ff0a8a9a01b0c1b82008ca59c (patch) | |
tree | c417e53b9a12ec5061d64dff8c7dbc5a5cce6d81 | |
parent | 5f5bcd549e2690e9cd040a1194faa77ed34a4403 (diff) | |
download | serenity-d93713b8744c025ff0a8a9a01b0c1b82008ca59c.zip |
LibJS: Implement the LocalTime, UTC, and TimeWithinDay AOs
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Date.cpp | 21 | ||||
-rw-r--r-- | Userland/Libraries/LibJS/Runtime/Date.h | 3 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 07e1193c1b..721131721d 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -337,6 +337,20 @@ double local_tza(double time, bool is_utc, Optional<StringView> time_zone_overri return is_utc ? offset : -offset; } +// 21.4.1.8 LocalTime ( t ), https://tc39.es/ecma262/#sec-localtime +double local_time(double time) +{ + // 1. Return t + LocalTZA(t, true). + return time + local_tza(time, true); +} + +// 21.4.1.9 UTC ( t ), https://tc39.es/ecma262/#sec-utc-t +double utc_time(double time) +{ + // 1. Return t - LocalTZA(t, false). + return time - local_tza(time, false); +} + // 21.4.1.11 MakeTime ( hour, min, sec, ms ), https://tc39.es/ecma262/#sec-maketime Value make_time(GlobalObject& global_object, Value hour, Value min, Value sec, Value ms) { @@ -365,6 +379,13 @@ double day(double time_value) return floor(time_value / MS_PER_DAY); } +// TimeWithinDay(t), https://tc39.es/ecma262/#eqn-TimeWithinDay +double time_within_day(double time) +{ + // 𝔽(ℝ(t) modulo ℝ(msPerDay)) + return modulo(time, MS_PER_DAY); +} + // 21.4.1.12 MakeDay ( year, month, date ), https://tc39.es/ecma262/#sec-makeday Value make_day(GlobalObject& global_object, Value year, Value month, Value date) { diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h index 26a38b083b..1829bcbc48 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.h +++ b/Userland/Libraries/LibJS/Runtime/Date.h @@ -105,7 +105,10 @@ u8 sec_from_time(double); u16 ms_from_time(double); u8 week_day(double); double local_tza(double time, bool is_utc, Optional<StringView> time_zone_override = {}); +double local_time(double time); +double utc_time(double time); double day(double); +double time_within_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); |