Debian Codegraph @

js/src/tests/non262/Intl/DateTimeFormat/formatRange-timeZoneName-matches-format.js

raw
1 // |reftest| skip-if(!this.hasOwnProperty("Intl"))
2
3 // Test DateTimeFormat.prototype.format and DateTimeFormat.prototype.formatRange
4 // use the same formatting for the "timeZoneName" option.
5
6 function hours(v) {
7 return v * 60 * 60 * 1000;
8 }
9
10 const locales = [
11 "en", "fr", "de", "es",
12 "ja", "th", "zh", "ar",
13 ];
14
15 const timeZones = [
16 "UTC", "Etc/GMT-1", "Etc/GMT+1",
17 "Africa/Cairo",
18 "America/New_York", "America/Los_Angeles",
19 "Asia/Riyadh", "Asia/Bangkok", "Asia/Shanghai", "Asia/Tokyo",
20 "Europe/Berlin", "Europe/London", "Europe/Madrid", "Europe/Paris",
21 ];
22
23 const timeZoneNames = [
24 "short", "shortOffset", "shortGeneric",
25 "long", "longOffset", "longGeneric",
26 ];
27
28 function timeZonePart(parts) {
29 return parts.filter(({type}) => type === "timeZoneName").map(({value}) => value)[0];
30 }
31
32 for (let locale of locales) {
33 for (let timeZone of timeZones) {
34 for (let timeZoneName of timeZoneNames) {
35 let dtf = new Intl.DateTimeFormat(locale, {timeZone, timeZoneName, hour: "numeric"});
36
37 let formatTimeZone = timeZonePart(dtf.formatToParts(0));
38 let formatRangeTimeZone = timeZonePart(dtf.formatRangeToParts(0, hours(1)));
39 assertEq(formatRangeTimeZone, formatTimeZone);
40 }
41 }
42 }
43
44 if (typeof reportCompare === "function")
45 reportCompare(0, 0, "ok");