summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Flynn <trflynn89@pm.me>2022-01-15 08:37:17 -0500
committerLinus Groh <mail@linusgroh.de>2022-01-15 20:13:48 +0100
commit032664332be6e1d42567165e9ffb623faf2b9a10 (patch)
treedbbb4ed7b3e5001d9b8f75e09a444781aa1ad2e7
parent11d7c7ebbd5d04a934f36f1dc446c1025eb832ae (diff)
downloadserenity-032664332be6e1d42567165e9ffb623faf2b9a10.zip
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.
-rw-r--r--Userland/Libraries/LibJS/Runtime/Date.cpp5
1 files changed, 4 insertions, 1 deletions
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<int>(ym) || !AK::is_within_range<int>(mn + 1))
return js_nan();
- auto t = days_since_epoch(static_cast<int>(ym), static_cast<int>(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<int>(ym), static_cast<int>(mn) + 1, 1) * Date::ms_per_day);
// 9. Return Day(t) + dt - 1𝔽.
return Value(day(static_cast<double>(t)) + dt - 1);