mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 19:38:12 +00:00
LibJS/Date: Ensure YearFromTime(t)
holds invariant after approximation
As of https://tc39.es/ecma262/#sec-yearfromtime, YearFromTime(t) should
return `y` such that `TimeFromYear(YearFromTime(t)) <= t`. This wasn't
held, since the approximation contained decimal digits that would nudge
the final value in the wrong direction.
Adapted from Kiesel:
6548a85743
Co-authored-by: Linus Groh <mail@linusgroh.de>
This commit is contained in:
parent
5870a1a9a1
commit
2086b8df9c
2 changed files with 10 additions and 1 deletions
|
@ -138,7 +138,7 @@ i32 year_from_time(double t)
|
|||
return NumericLimits<i32>::max();
|
||||
|
||||
// Approximation using average number of milliseconds per year. We might have to adjust this guess afterwards.
|
||||
auto year = static_cast<i32>(t / (365.2425 * ms_per_day) + 1970);
|
||||
auto year = static_cast<i32>(floor(t / (365.2425 * ms_per_day) + 1970));
|
||||
|
||||
auto year_t = time_from_year(year);
|
||||
if (year_t > t)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue