mirror of
https://github.com/SerenityOS/serenity
synced 2024-10-16 04:42:57 +00:00
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:
parent
bfb36fec89
commit
37146e305a
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue