mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 02:57:44 +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
1 changed files with 1 additions and 1 deletions
|
@ -205,7 +205,7 @@ double day_from_year(i32 y)
|
||||||
i32 year_from_time(double t)
|
i32 year_from_time(double t)
|
||||||
{
|
{
|
||||||
// the largest integral Number y (closest to +∞) such that TimeFromYear(y) ≤ 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
|
// InLeapYear(t), https://tc39.es/ecma262/#eqn-InLeapYear
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue