From 032664332be6e1d42567165e9ffb623faf2b9a10 Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Sat, 15 Jan 2022 08:37:17 -0500 Subject: [PATCH] LibJS: Implement MakeDay without using AK::years_to_days_since_epoch Implementing years_to_days_since_epoch without a loop will be tricky. The TimeFromYear AO gives a good enough approximation for MakeDay until we figure that out. --- Userland/Libraries/LibJS/Runtime/Date.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibJS/Runtime/Date.cpp b/Userland/Libraries/LibJS/Runtime/Date.cpp index a48c5c24c1..96706e5fb4 100644 --- a/Userland/Libraries/LibJS/Runtime/Date.cpp +++ b/Userland/Libraries/LibJS/Runtime/Date.cpp @@ -341,7 +341,10 @@ 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(ym) || !AK::is_within_range(mn + 1)) return js_nan(); - auto t = days_since_epoch(static_cast(ym), static_cast(mn) + 1, 1) * Date::ms_per_day; + + // FIXME: We are avoiding AK::years_to_days_since_epoch here because it is implemented by looping over + // the range [1970, ym), which will spin for any time value with an extremely large year. + auto t = time_from_year(ym) + (day_of_year(static_cast(ym), static_cast(mn) + 1, 1) * Date::ms_per_day); // 9. Return Day(t) + dt - 1𝔽. return Value(day(static_cast(t)) + dt - 1);