summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/formatRange-timeZoneName.js
blob: c99799d487a995fc199f87e7d7438eb9c96708b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

// Test all "timeZoneName" options with various locales when formatting a
// date-time range.

const {
  Hour, Minute, Literal, TimeZoneName,
} = DateTimeFormatParts;

function hours(v) {
  return v * 60 * 60 * 1000;
}

function minutes(v) {
  return v * 60 * 1000;
}

const tests = {
  "en": [
    {
      start: 0,
      end: minutes(2),
      timeZone: "UTC",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("UTC")],
        shortOffset: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT")],
        shortGeneric: "shortOffset",
        long: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Coordinated Universal Time")],
        longOffset: "shortOffset",
        longGeneric: "shortOffset",
      },
    },
    {
      start: 0,
      end: minutes(2),
      timeZone: "America/New_York",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("EST")],
        shortOffset: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT-5")],
        shortGeneric: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("ET")],
        long: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Eastern Standard Time")],
        longOffset: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT-05:00")],
        longGeneric: [Hour("19"), Literal(":"), Minute("00"), Literal(" – "), Hour("19"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Eastern Time")],
      },
    },
  ],
  "fr": [
    {
      start: 0,
      end: hours(2),
      timeZone: "UTC",
      options: {hour: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("00"), Literal(" – "), Hour("02"), Literal(" "), TimeZoneName("UTC")],
        shortOffset: "short",
        shortGeneric: "short",
        long: [Hour("00"), Literal(" – "), Hour("02"), Literal(" "), TimeZoneName("temps universel coordonné")],
        longOffset: "short",
        longGeneric: "short",
      },
    },
    {
      start: minutes(15),
      end: hours(5) + minutes(30),
      timeZone: "Europe/Paris",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("UTC+1")],
        shortOffset: "short",
        shortGeneric: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("heure : France")],
        long: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("heure normale d’Europe centrale")],
        longOffset: [Hour("01"), Literal(":"), Minute("15"), Literal(" – "), Hour("06"), Literal(":"), Minute("30"), Literal(" "), TimeZoneName("UTC+01:00")],
        longGeneric: "long",
      },
    },
  ],
  "de": [
    {
      start: 0,
      end: hours(2),
      timeZone: "UTC",
      options: {hour: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("00"), Literal("–"), Hour("02"), Literal(" Uhr "), TimeZoneName("UTC")],
        shortOffset: [Hour("00"), Literal("–"), Hour("02"), Literal(" Uhr "), TimeZoneName("GMT")],
        shortGeneric: "shortOffset",
        long: [Hour("00"), Literal("–"), Hour("02"), Literal(" Uhr "), TimeZoneName("Koordinierte Weltzeit")],
        longOffset: "shortOffset",
        longGeneric: "shortOffset",
      },
    },
    {
      start: hours(5) + minutes(15),
      end: hours(5) + minutes(30),
      timeZone: "Europe/Berlin",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("MEZ")],
        shortOffset: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("GMT+1")],
        shortGeneric: "short",
        long: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("Mitteleuropäische Normalzeit")],
        longOffset: [Hour("06"), Literal(":"), Minute("15"), Literal("–"), Hour("06"), Literal(":"), Minute("30"), Literal(" Uhr "), TimeZoneName("GMT+01:00")],
        longGeneric: "long",
      },
    },
  ],
};

for (let [locale, formats] of Object.entries(tests)) {
  for (let {start, end, timeZone, options, timeZoneNames} of formats) {
    for (let [timeZoneName, format] of Object.entries(timeZoneNames)) {
      let df = new Intl.DateTimeFormat(locale, {timeZone, timeZoneName, ...options});
      if (typeof format === "string") {
        format = timeZoneNames[format];
      }
      assertRangeParts(df, start, end, format);
    }
  }
}

if (typeof reportCompare === "function")
  reportCompare(0, 0, "ok");