mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:17:46 +00:00
LibJS: Implement Date.UTC according to the spec
This fixes all failing Date.UTC test262 tests, which failed due to not handling invalid input and evaluating inputs out of order. But this also avoids using timegm(), which doesn't work on macOS for years before 1900 (they simply return -1 for those years). Partially addresses #4651. Date.parse.js still fails.
This commit is contained in:
parent
7a0830bb24
commit
260d2099da
2 changed files with 48 additions and 15 deletions
|
@ -53,3 +53,20 @@ test("out of range", () => {
|
|||
expect(Date.UTC(2020, 1, 15, 12, 30, 30, -2345)).toBe(1581769827655);
|
||||
expect(Date.UTC(2020, 1, 15, 12, 30, 30, 2345)).toBe(1581769832345);
|
||||
});
|
||||
|
||||
test("special values", () => {
|
||||
[Infinity, -Infinity, NaN].forEach(value => {
|
||||
expect(Date.UTC(value)).toBeNaN();
|
||||
expect(Date.UTC(0, value)).toBeNaN();
|
||||
expect(Date.UTC(0, 0, value)).toBeNaN();
|
||||
expect(Date.UTC(0, 0, 1, value)).toBeNaN();
|
||||
expect(Date.UTC(0, 0, 1, 0, value)).toBeNaN();
|
||||
expect(Date.UTC(0, 0, 1, 0, 0, value)).toBeNaN();
|
||||
expect(Date.UTC(0, 0, 1, 0, 0, 0, value)).toBeNaN();
|
||||
});
|
||||
});
|
||||
|
||||
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();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue