Debian Codegraph @

js/src/tests/non262/Intl/DateTimeFormat/tz-environment-variable.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl")||(winWidget&&!xulRuntime.shell)) -- Windows browser in automation doesn't pick up new time zones correctly
2
3 // From bug 1330149:
4 //
5 // Windows only supports a very limited set of IANA time zone names for the TZ
6 // environment variable.
7 //
8 // TZ format supported by Windows: "TZ=tzn[+|-]hh[:mm[:ss]][dzn]".
9 //
10 // Complete list of all IANA time zone ids matching that format.
11 //
12 // From tzdata's "northamerica" file:
13 // EST5EDT
14 // CST6CDT
15 // MST7MDT
16 // PST8PDT
17 //
18 // From tzdata's "backward" file:
19 // GMT+0
20 // GMT-0
21 // GMT0
22 //
23 // Also supported on Windows even though they don't match the format listed
24 // above.
25 //
26 // From tzdata's "backward" file:
27 // UCT
28 // UTC
29 //
30 // From tzdata's "etcetera" file:
31 // GMT
32
33 function inTimeZone(tzname, fn) {
34 setTimeZone(tzname);
35 try {
36 fn();
37 } finally {
38 setTimeZone("PST8PDT");
39 }
40 }
41
42 const timeZones = [
43 { id: "EST5EDT", normalized: "America/New_York" },
44 { id: "CST6CDT", normalized: "America/Chicago" },
45 { id: "MST7MDT", normalized: "America/Denver" },
46 { id: "PST8PDT", normalized: "America/Los_Angeles" },
47 // ICU on non-Windows platforms doesn't accept these three time zone
48 // identifiers, cf. isValidOlsonID in $ICU/source/common/putil.cpp. We
49 // could add support for them, but it seems unlikely they're used in
50 // practice, so we just skip over them.
51 // { id: "GMT+0", normalized: "UTC" },
52 // { id: "GMT-0", normalized: "UTC" },
53 // { id: "GMT0", normalized: "UTC" },
54 { id: "UCT", normalized: "UTC" },
55 { id: "UTC", normalized: "UTC" },
56 { id: "GMT", normalized: "UTC" },
57 ];
58
59 for (let {id, normalized = id} of timeZones) {
60 inTimeZone(id, () => {
61 let opts = new Intl.DateTimeFormat().resolvedOptions();
62 assertEq(opts.timeZone, normalized);
63 });
64 }
65
66 if (typeof reportCompare === "function")
67 reportCompare(0, 0, "ok");