LibJS: Account for leap days in year_from_time()

A year has 365.2425 days, not 365. This lead to off-by-one results for
time values (milliseconds) near the end of a year, which would lead to
calculation issues and crashes in other AOs.

Fixes #10796.
This commit is contained in:
Linus Groh 2021-11-05 01:09:18 +01:00
parent bfb36fec89
commit 37146e305a

View file

@ -205,7 +205,7 @@ double day_from_year(i32 y)
i32 year_from_time(double t)
{
// the largest integral Number y (closest to +∞) such that TimeFromYear(y) ≤ t
return static_cast<i32>(t / (365.0 * MS_PER_DAY) + 1970);
return static_cast<i32>(t / (365.2425 * MS_PER_DAY) + 1970);
}
// InLeapYear(t), https://tc39.es/ecma262/#eqn-InLeapYear