Debian Codegraph @

js/src/tests/non262/Temporal/Intl/date.js

raw
1 // |reftest| shell-option(--enable-temporal) skip-if(!this.hasOwnProperty("Temporal")||!this.hasOwnProperty("Intl"))
2
3 // Test Temporal types which can produce date formats.
4
5 const locales = [
6 "en",
7 "de",
8 "fr",
9 "es",
10 "ar",
11 "th",
12 "zh",
13 "ja",
14 ];
15
16 const options = [
17 {
18 weekday: "long",
19 year: "numeric",
20 month: "long",
21 day: "numeric",
22 },
23 {
24 year: "numeric",
25 month: "short",
26 day: "numeric",
27 },
28 {
29 year: "2-digit",
30 month: "narrow",
31 },
32 {
33 month: "2-digit",
34 day: "2-digit",
35 },
36
37 {
38 era: "long",
39 year: "numeric",
40 },
41 {
42 era: "short",
43 year: "numeric",
44 month: "numeric",
45 },
46 ];
47
48 const timeZone = "UTC";
49
50 let date = new Date(0);
51 let instant = date.toTemporalInstant();
52 let zonedDateTime = instant.toZonedDateTimeISO(timeZone);
53 let plainDateTime = zonedDateTime.toPlainDateTime();
54 let plainDate = zonedDateTime.toPlainDate();
55
56 for (let locale of locales) {
57 let expected = date.toLocaleDateString(locale, {timeZone});
58 assertEq(plainDate.toLocaleString(locale, {timeZone}), expected);
59
60 for (let opts of options) {
61 let expected = date.toLocaleDateString(locale, {timeZone, ...opts});
62 assertEq(instant.toLocaleString(locale, {timeZone, ...opts}), expected);
63 assertEq(zonedDateTime.toLocaleString(locale, {...opts}), expected);
64 assertEq(plainDateTime.toLocaleString(locale, {timeZone, ...opts}), expected);
65 assertEq(plainDate.toLocaleString(locale, {timeZone, ...opts}), expected);
66 }
67 }
68
69 if (typeof reportCompare === "function")
70 reportCompare(true, true);