From 28a9a248d637a3deded706f84d0f9eae8116c3e9 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Sat, 30 Oct 2021 09:10:34 +0200 Subject: [PATCH] LibJS: Fix off-by-one in make_day()'s temporary Core::DateTime Just like in the previous commit, the day value of Core::DateTime is one-based, not zero based. Noticed while implementing a new Temporal function, this likely would've been caught earlier if we'd also use it for the Date API (we don't). --- Userland/Libraries/LibJS/Runtime/Date.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index 35f9327931..6a54ca3885 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -341,7 +341,7 @@ Value make_day(GlobalObject& global_object, Value year, Value month, Value date) // 8. Find a finite time value t such that YearFromTime(t) is ym and MonthFromTime(t) is mn and DateFromTime(t) is 1𝔽; but if this is not possible (because some argument is out of range), return NaN. if (!AK::is_within_range(y) || !AK::is_within_range(m + 1)) return js_nan(); - auto t = Core::DateTime::create(static_cast(y), static_cast(m + 1), 0).timestamp() * 1000; + auto t = Core::DateTime::create(static_cast(y), static_cast(m + 1), 1).timestamp() * 1000; // 9. Return Day(t) + dt - 1𝔽. return Value(day(static_cast(t)) + dt - 1); }