mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 21:37:35 +00:00
LibJS: Ensure Date tests can pass in any time zone by testing UTC values
When we create a Date object from a timestamp, or set its value by way of Date.prototype.setTime, the timestamp is interpreted as UTC. Change test expecatations against such instances to use UTC as well.
This commit is contained in:
parent
8a27180fb8
commit
24459a44b0
2 changed files with 10 additions and 12 deletions
|
@ -14,16 +14,14 @@ test("timestamp constructor", () => {
|
|||
// The timestamp constructor takes a timestamp in milliseconds since the start of the epoch, in UTC.
|
||||
|
||||
// 50 days and 1234 milliseconds after the start of the epoch.
|
||||
// Most Date methods return values in local time, but since timezone offsets are less than 17 days,
|
||||
// these checks will pass in all timezones.
|
||||
let timestamp = 50 * 24 * 60 * 60 * 1000 + 1234;
|
||||
|
||||
let date = new Date(timestamp);
|
||||
expect(date.getTime()).toBe(timestamp); // getTime() returns the timestamp in UTC.
|
||||
expect(date.getMilliseconds()).toBe(234);
|
||||
expect(date.getSeconds()).toBe(1);
|
||||
expect(date.getFullYear()).toBe(1970);
|
||||
expect(date.getMonth()).toBe(1); // Feb
|
||||
expect(date.getUTCMilliseconds()).toBe(234);
|
||||
expect(date.getUTCSeconds()).toBe(1);
|
||||
expect(date.getUTCFullYear()).toBe(1970);
|
||||
expect(date.getUTCMonth()).toBe(1); // Feb
|
||||
|
||||
date = new Date(NaN);
|
||||
expect(date.getTime()).toBe(NaN);
|
||||
|
|
|
@ -22,9 +22,9 @@ test("Timestamp as argument", () => {
|
|||
let date = new Date(2021, 0, 1);
|
||||
|
||||
date.setTime(1622993746000);
|
||||
expect(date.getDate()).toBe(6);
|
||||
expect(date.getMonth()).toBe(5);
|
||||
expect(date.getFullYear()).toBe(2021);
|
||||
expect(date.getUTCDate()).toBe(6);
|
||||
expect(date.getUTCMonth()).toBe(5);
|
||||
expect(date.getUTCFullYear()).toBe(2021);
|
||||
expect(date.getUTCHours()).toBe(15);
|
||||
expect(date.getUTCMinutes()).toBe(35);
|
||||
expect(date.getUTCSeconds()).toBe(46);
|
||||
|
@ -37,9 +37,9 @@ test("Make Invalid Date valid again", () => {
|
|||
expect(date.getTime()).toBe(NaN);
|
||||
|
||||
date.setTime(1622993746000);
|
||||
expect(date.getDate()).toBe(6);
|
||||
expect(date.getMonth()).toBe(5);
|
||||
expect(date.getFullYear()).toBe(2021);
|
||||
expect(date.getUTCDate()).toBe(6);
|
||||
expect(date.getUTCMonth()).toBe(5);
|
||||
expect(date.getUTCFullYear()).toBe(2021);
|
||||
expect(date.getUTCHours()).toBe(15);
|
||||
expect(date.getUTCMinutes()).toBe(35);
|
||||
expect(date.getUTCSeconds()).toBe(46);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue