mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 07:27:45 +00:00
LibC: Make localtime() and gmtime() handle years before 1970
Year computation has to be based on seconds, not days, in case t is < 0 but t / __seconds_per_day is 0. Year computation also has to consider negative timestamps. With this, days is always positive and <= the number of days in the year, so base the tm_wday computation directly on the timestamp, and do it first, before t is modified in the year computation. In C, % can return a negative number if the left operand is negative, compensate for that. Tested via test-js. (Except for tm_wday, since we don't implement Date.prototype.getUTCDate() yet.)
This commit is contained in:
parent
fc28c9b085
commit
5f595e7e1b
2 changed files with 16 additions and 10 deletions
|
@ -1,9 +1,7 @@
|
|||
test("basic functionality", () => {
|
||||
expect(new Date(1597955034555).toISOString()).toBe("2020-08-20T20:23:54.555Z");
|
||||
|
||||
// FIXME: Add these once they work.
|
||||
//expect(new Date(Date.UTC(22020)).toISOString()).toBe("+022020-01-01T00:00:00.000Z");
|
||||
//expect(new Date(Date.UTC(1950)).toISOString()).toBe("1950-01-01T00:00:00.000Z");
|
||||
//expect(new Date(Date.UTC(1800)).toISOString()).toBe("1800-01-01T00:00:00.000Z");
|
||||
//expect(new Date(Date.UTC(-100)).toISOString()).toBe("-000100-01-01T00:00:00.000Z");
|
||||
expect(new Date(Date.UTC(22020)).toISOString()).toBe("+022020-01-01T00:00:00.000Z");
|
||||
expect(new Date(Date.UTC(1950)).toISOString()).toBe("1950-01-01T00:00:00.000Z");
|
||||
expect(new Date(Date.UTC(1800)).toISOString()).toBe("1800-01-01T00:00:00.000Z");
|
||||
expect(new Date(Date.UTC(-100)).toISOString()).toBe("-000100-01-01T00:00:00.000Z");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue