mirror of
https://github.com/RGBCube/serenity
synced 2025-06-01 08:28:11 +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
|
@ -70,3 +70,12 @@ test("time clip", () => {
|
|||
expect(Date.UTC(275760, 8, 13, 0, 0, 0, 0)).toBe(8.64e15);
|
||||
expect(Date.UTC(275760, 8, 13, 0, 0, 0, 1)).toBeNaN();
|
||||
});
|
||||
|
||||
test("YearFromTime invariant holds with negative times", () => {
|
||||
// https://tc39.es/ecma262/#sec-yearfromtime: YearFromTime(t) should return
|
||||
// a value such that TimeFromYear(YearFromTime(t)) <= t.
|
||||
//
|
||||
// If this doesn't hold, then the following Date constructor will result in
|
||||
// a crash from an assertion (#21548).
|
||||
new Date(Date.UTC(-1112, 11, 31));
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue