Browse Source

LibJS: Change test conditions to pass in all time zones

Mostly slapping "timeZone: UTC" on DateTimeFormat tests (we have other
tests for specific time zones). Also pick dates that are not on DST
boundaries in some time zones where that matters.
Timothy Flynn 3 years ago
parent
commit
9cd93944b8

+ 1 - 1
Userland/Libraries/LibJS/Tests/builtins/Date/Date.prototype.setHours.js

@@ -1,5 +1,5 @@
 test("basic functionality", () => {
-    let d = new Date(2000, 2, 1);
+    let d = new Date(2000, 11, 15);
 
     d.setHours(2);
     expect(d.getHours()).toBe(2);

+ 14 - 8
Userland/Libraries/LibJS/Tests/builtins/Date/Date.prototype.toLocaleDateString.js

@@ -37,20 +37,26 @@ describe("correct behavior", () => {
     const d1 = new Date(Date.UTC(1989, 0, 23, 7, 8, 9, 45));
 
     test("defaults to date", () => {
-        expect(d0.toLocaleDateString("en")).toBe("12/7/2021");
-        expect(d1.toLocaleDateString("en")).toBe("1/23/1989");
+        expect(d0.toLocaleDateString("en", { timeZone: "UTC" })).toBe("12/7/2021");
+        expect(d1.toLocaleDateString("en", { timeZone: "UTC" })).toBe("1/23/1989");
 
-        expect(d0.toLocaleDateString("ar")).toBe("٧‏/١٢‏/٢٠٢١");
-        expect(d1.toLocaleDateString("ar")).toBe("٢٣‏/١‏/١٩٨٩");
+        expect(d0.toLocaleDateString("ar", { timeZone: "UTC" })).toBe("٧‏/١٢‏/٢٠٢١");
+        expect(d1.toLocaleDateString("ar", { timeZone: "UTC" })).toBe("٢٣‏/١‏/١٩٨٩");
     });
 
     test("dateStyle may be set", () => {
-        expect(d0.toLocaleDateString("en", { dateStyle: "full" })).toBe(
+        expect(d0.toLocaleDateString("en", { dateStyle: "full", timeZone: "UTC" })).toBe(
             "Tuesday, December 7, 2021"
         );
-        expect(d1.toLocaleDateString("en", { dateStyle: "full" })).toBe("Monday, January 23, 1989");
+        expect(d1.toLocaleDateString("en", { dateStyle: "full", timeZone: "UTC" })).toBe(
+            "Monday, January 23, 1989"
+        );
 
-        expect(d0.toLocaleDateString("ar", { dateStyle: "full" })).toBe("الثلاثاء، ٧ ديسمبر ٢٠٢١");
-        expect(d1.toLocaleDateString("ar", { dateStyle: "full" })).toBe("الاثنين، ٢٣ يناير ١٩٨٩");
+        expect(d0.toLocaleDateString("ar", { dateStyle: "full", timeZone: "UTC" })).toBe(
+            "الثلاثاء، ٧ ديسمبر ٢٠٢١"
+        );
+        expect(d1.toLocaleDateString("ar", { dateStyle: "full", timeZone: "UTC" })).toBe(
+            "الاثنين، ٢٣ يناير ١٩٨٩"
+        );
     });
 });

+ 12 - 12
Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.format.js

@@ -48,11 +48,11 @@ describe("dateStyle", () => {
 
     test("all", () => {
         data.forEach(d => {
-            const en = new Intl.DateTimeFormat("en", { dateStyle: d.date });
+            const en = new Intl.DateTimeFormat("en", { dateStyle: d.date, timeZone: "UTC" });
             expect(en.format(d0)).toBe(d.en0);
             expect(en.format(d1)).toBe(d.en1);
 
-            const ar = new Intl.DateTimeFormat("ar", { dateStyle: d.date });
+            const ar = new Intl.DateTimeFormat("ar", { dateStyle: d.date, timeZone: "UTC" });
             expect(ar.format(d0)).toBe(d.ar0);
             expect(ar.format(d1)).toBe(d.ar1);
         });
@@ -131,11 +131,11 @@ describe("weekday", () => {
 
     test("all", () => {
         data.forEach(d => {
-            const en = new Intl.DateTimeFormat("en", { weekday: d.weekday });
+            const en = new Intl.DateTimeFormat("en", { weekday: d.weekday, timeZone: "UTC" });
             expect(en.format(d0)).toBe(d.en0);
             expect(en.format(d1)).toBe(d.en1);
 
-            const ar = new Intl.DateTimeFormat("ar", { weekday: d.weekday });
+            const ar = new Intl.DateTimeFormat("ar", { weekday: d.weekday, timeZone: "UTC" });
             expect(ar.format(d0)).toBe(d.ar0);
             expect(ar.format(d1)).toBe(d.ar1);
         });
@@ -152,11 +152,11 @@ describe("era", () => {
 
     test("all", () => {
         data.forEach(d => {
-            const en = new Intl.DateTimeFormat("en", { era: d.era });
+            const en = new Intl.DateTimeFormat("en", { era: d.era, timeZone: "UTC" });
             expect(en.format(d0)).toBe(d.en0);
             expect(en.format(d1)).toBe(d.en1);
 
-            const ar = new Intl.DateTimeFormat("ar", { era: d.era });
+            const ar = new Intl.DateTimeFormat("ar", { era: d.era, timeZone: "UTC" });
             expect(ar.format(d0)).toBe(d.ar0);
             expect(ar.format(d1)).toBe(d.ar1);
         });
@@ -172,11 +172,11 @@ describe("year", () => {
 
     test("all", () => {
         data.forEach(d => {
-            const en = new Intl.DateTimeFormat("en", { year: d.year });
+            const en = new Intl.DateTimeFormat("en", { year: d.year, timeZone: "UTC" });
             expect(en.format(d0)).toBe(d.en0);
             expect(en.format(d1)).toBe(d.en1);
 
-            const ar = new Intl.DateTimeFormat("ar", { year: d.year });
+            const ar = new Intl.DateTimeFormat("ar", { year: d.year, timeZone: "UTC" });
             expect(ar.format(d0)).toBe(d.ar0);
             expect(ar.format(d1)).toBe(d.ar1);
         });
@@ -195,11 +195,11 @@ describe("month", () => {
 
     test("all", () => {
         data.forEach(d => {
-            const en = new Intl.DateTimeFormat("en", { month: d.month });
+            const en = new Intl.DateTimeFormat("en", { month: d.month, timeZone: "UTC" });
             expect(en.format(d0)).toBe(d.en0);
             expect(en.format(d1)).toBe(d.en1);
 
-            const ar = new Intl.DateTimeFormat("ar", { month: d.month });
+            const ar = new Intl.DateTimeFormat("ar", { month: d.month, timeZone: "UTC" });
             expect(ar.format(d0)).toBe(d.ar0);
             expect(ar.format(d1)).toBe(d.ar1);
         });
@@ -215,11 +215,11 @@ describe("day", () => {
 
     test("all", () => {
         data.forEach(d => {
-            const en = new Intl.DateTimeFormat("en", { day: d.day });
+            const en = new Intl.DateTimeFormat("en", { day: d.day, timeZone: "UTC" });
             expect(en.format(d0)).toBe(d.en0);
             expect(en.format(d1)).toBe(d.en1);
 
-            const ar = new Intl.DateTimeFormat("ar", { day: d.day });
+            const ar = new Intl.DateTimeFormat("ar", { day: d.day, timeZone: "UTC" });
             expect(ar.format(d0)).toBe(d.ar0);
             expect(ar.format(d1)).toBe(d.ar1);
         });

+ 4 - 2
Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.formatRange.js

@@ -53,6 +53,7 @@ describe("equal dates are squashed", () => {
             year: "numeric",
             month: "long",
             day: "2-digit",
+            timeZone: "UTC",
         });
         expect(en.formatRange(d0, d0)).toBe("January 23, 1989");
         expect(en.formatRange(d1, d1)).toBe("December 07, 2021");
@@ -61,6 +62,7 @@ describe("equal dates are squashed", () => {
             year: "numeric",
             month: "long",
             day: "2-digit",
+            timeZone: "UTC",
         });
         expect(ja.formatRange(d0, d0)).toBe("1989/1月/23");
         expect(ja.formatRange(d1, d1)).toBe("2021/12月/07");
@@ -142,7 +144,7 @@ describe("dateStyle", () => {
 
     test("all", () => {
         data.forEach(d => {
-            const en = new Intl.DateTimeFormat("en", { dateStyle: d.date });
+            const en = new Intl.DateTimeFormat("en", { dateStyle: d.date, timeZone: "UTC" });
             expect(en.formatRange(d0, d1)).toBe(d.en);
 
             // If this test is to be changed, take care to note the "long" style for the ja locale is an intentionally
@@ -151,7 +153,7 @@ describe("dateStyle", () => {
             // "y/MM/dd~y/MM/dd" - the month field there conflicts with a 2-digit style. This exercises the step in the
             // FormatDateTimePattern AO to choose the style from rangeFormatOptions instead of dateTimeFormat (step 15.f.i
             // as of when this test was written).
-            const ja = new Intl.DateTimeFormat("ja", { dateStyle: d.date });
+            const ja = new Intl.DateTimeFormat("ja", { dateStyle: d.date, timeZone: "UTC" });
             expect(ja.formatRange(d0, d1)).toBe(d.ja);
         });
     });

+ 10 - 8
Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.formatRangeToParts.js

@@ -53,6 +53,7 @@ describe("equal dates are squashed", () => {
             year: "numeric",
             month: "long",
             day: "2-digit",
+            timeZone: "UTC",
         });
         expect(en.formatRangeToParts(d0, d0)).toEqual([
             { type: "month", value: "January", source: "shared" },
@@ -66,6 +67,7 @@ describe("equal dates are squashed", () => {
             year: "numeric",
             month: "long",
             day: "2-digit",
+            timeZone: "UTC",
         });
         expect(ja.formatRangeToParts(d0, d0)).toEqual([
             { type: "year", value: "1989", source: "shared" },
@@ -207,7 +209,7 @@ describe("equal dates are squashed", () => {
 
 describe("dateStyle", () => {
     test("full", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "full" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "full", timeZone: "UTC" });
         expect(en.formatRangeToParts(d0, d1)).toEqual([
             { type: "weekday", value: "Monday", source: "startRange" },
             { type: "literal", value: ", ", source: "startRange" },
@@ -226,7 +228,7 @@ describe("dateStyle", () => {
             { type: "year", value: "2021", source: "endRange" },
         ]);
 
-        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "full" });
+        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "full", timeZone: "UTC" });
         expect(ja.formatRangeToParts(d0, d1)).toEqual([
             { type: "year", value: "1989", source: "startRange" },
             { type: "literal", value: "年", source: "startRange" },
@@ -247,7 +249,7 @@ describe("dateStyle", () => {
     });
 
     test("long", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "long" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "long", timeZone: "UTC" });
         expect(en.formatRangeToParts(d0, d1)).toEqual([
             { type: "month", value: "January", source: "startRange" },
             { type: "literal", value: " ", source: "startRange" },
@@ -262,7 +264,7 @@ describe("dateStyle", () => {
             { type: "year", value: "2021", source: "endRange" },
         ]);
 
-        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "long" });
+        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "long", timeZone: "UTC" });
         expect(ja.formatRangeToParts(d0, d1)).toEqual([
             { type: "year", value: "1989", source: "startRange" },
             { type: "literal", value: "/", source: "startRange" },
@@ -279,7 +281,7 @@ describe("dateStyle", () => {
     });
 
     test("medium", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "medium" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "medium", timeZone: "UTC" });
         expect(en.formatRangeToParts(d0, d1)).toEqual([
             { type: "month", value: "Jan", source: "startRange" },
             { type: "literal", value: " ", source: "startRange" },
@@ -294,7 +296,7 @@ describe("dateStyle", () => {
             { type: "year", value: "2021", source: "endRange" },
         ]);
 
-        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "medium" });
+        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "medium", timeZone: "UTC" });
         expect(ja.formatRangeToParts(d0, d1)).toEqual([
             { type: "year", value: "1989", source: "startRange" },
             { type: "literal", value: "/", source: "startRange" },
@@ -311,7 +313,7 @@ describe("dateStyle", () => {
     });
 
     test("short", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "short" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "short", timeZone: "UTC" });
         expect(en.formatRangeToParts(d0, d1)).toEqual([
             { type: "month", value: "1", source: "startRange" },
             { type: "literal", value: "/", source: "startRange" },
@@ -326,7 +328,7 @@ describe("dateStyle", () => {
             { type: "year", value: "21", source: "endRange" },
         ]);
 
-        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "short" });
+        const ja = new Intl.DateTimeFormat("ja", { dateStyle: "short", timeZone: "UTC" });
         expect(ja.formatRangeToParts(d0, d1)).toEqual([
             { type: "year", value: "1989", source: "startRange" },
             { type: "literal", value: "/", source: "startRange" },

+ 8 - 8
Userland/Libraries/LibJS/Tests/builtins/Intl/DateTimeFormat/DateTimeFormat.prototype.formatToParts.js

@@ -34,7 +34,7 @@ const d = Date.UTC(1989, 0, 23, 7, 8, 9, 45);
 
 describe("dateStyle", () => {
     test("full", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "full" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "full", timeZone: "UTC" });
         expect(en.formatToParts(d)).toEqual([
             { type: "weekday", value: "Monday" },
             { type: "literal", value: ", " },
@@ -45,7 +45,7 @@ describe("dateStyle", () => {
             { type: "year", value: "1989" },
         ]);
 
-        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "full" });
+        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "full", timeZone: "UTC" });
         expect(ar.formatToParts(d)).toEqual([
             { type: "weekday", value: "الاثنين" },
             { type: "literal", value: "، " },
@@ -58,7 +58,7 @@ describe("dateStyle", () => {
     });
 
     test("long", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "long" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "long", timeZone: "UTC" });
         expect(en.formatToParts(d)).toEqual([
             { type: "month", value: "January" },
             { type: "literal", value: " " },
@@ -67,7 +67,7 @@ describe("dateStyle", () => {
             { type: "year", value: "1989" },
         ]);
 
-        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "long" });
+        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "long", timeZone: "UTC" });
         expect(ar.formatToParts(d)).toEqual([
             { type: "day", value: "٢٣" },
             { type: "literal", value: " " },
@@ -78,7 +78,7 @@ describe("dateStyle", () => {
     });
 
     test("medium", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "medium" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "medium", timeZone: "UTC" });
         expect(en.formatToParts(d)).toEqual([
             { type: "month", value: "Jan" },
             { type: "literal", value: " " },
@@ -87,7 +87,7 @@ describe("dateStyle", () => {
             { type: "year", value: "1989" },
         ]);
 
-        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "medium" });
+        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "medium", timeZone: "UTC" });
         expect(ar.formatToParts(d)).toEqual([
             { type: "day", value: "٢٣" },
             { type: "literal", value: "‏/" },
@@ -98,7 +98,7 @@ describe("dateStyle", () => {
     });
 
     test("short", () => {
-        const en = new Intl.DateTimeFormat("en", { dateStyle: "short" });
+        const en = new Intl.DateTimeFormat("en", { dateStyle: "short", timeZone: "UTC" });
         expect(en.formatToParts(d)).toEqual([
             { type: "month", value: "1" },
             { type: "literal", value: "/" },
@@ -107,7 +107,7 @@ describe("dateStyle", () => {
             { type: "year", value: "89" },
         ]);
 
-        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "short" });
+        const ar = new Intl.DateTimeFormat("ar", { dateStyle: "short", timeZone: "UTC" });
         expect(ar.formatToParts(d)).toEqual([
             { type: "day", value: "٢٣" },
             { type: "literal", value: "‏/" },