From baf3f3bd6e6d0f46ff958ecec0858f00474bca93 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Mon, 6 Dec 2021 12:59:52 -0500 Subject: [PATCH] LibJS: Implement Date's Week Day AO --- Userland/Libraries/LibJS/Runtime/Date.cpp | 7 +++++++ Userland/Libraries/LibJS/Runtime/Date.h | 1 + 2 files changed, 8 insertions(+) diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 9d6337caa3..95770459f8 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -307,6 +307,13 @@ u16 ms_from_time(double t) return static_cast(modulo(t, MS_PER_SECOND)); } +// 21.4.1.6 Week Day, https://tc39.es/ecma262/#sec-week-day +u8 week_day(double t) +{ + // 𝔽(ℝ(Day(t) + 4𝔽) modulo 7) + return static_cast(modulo(day(t) + 4, 7.0)); +} + // 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) { diff --git a/Userland/Libraries/LibJS/Runtime/Date.h b/Userland/Libraries/LibJS/Runtime/Date.h index f2bb4b7a5a..9251a4074b 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.h +++ b/Userland/Libraries/LibJS/Runtime/Date.h @@ -98,6 +98,7 @@ u8 hour_from_time(double); u8 min_from_time(double); u8 sec_from_time(double); u16 ms_from_time(double); +u8 week_day(double); 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);