summaryrefslogtreecommitdiff
path: root/Libraries/LibJS/Tests
diff options
context:
space:
mode:
authorNico Weber <thakis@chromium.org>2020-08-22 22:15:00 -0400
committerAndreas Kling <kling@serenityos.org>2020-08-23 10:42:37 +0200
commit5f595e7e1b15791d32beb9737c3c0cf4fa7cbf38 (patch)
treed38fe617a52e1124a90fdd16009beca82b8a9415 /Libraries/LibJS/Tests
parentfc28c9b085380240210a9b623a12232bf33c787b (diff)
downloadserenity-5f595e7e1b15791d32beb9737c3c0cf4fa7cbf38.zip
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.)
Diffstat (limited to 'Libraries/LibJS/Tests')
-rw-r--r--Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js10
1 files changed, 4 insertions, 6 deletions
diff --git a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js
index f929540f99..2b380fc24d 100644
--- a/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js
+++ b/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toISOString.js
@@ -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");
});