summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/format-timeZone-offset.js
blob: ed28a52c696152949475ee7bb7b492d2a7f6b0ed (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
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

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

const tests = {
  "en": [
    {
      date: 0,
      timeZone: "-23",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("GMT-23")],
        shortOffset: "short",
        shortGeneric: "short",
        long: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("GMT-23:00")],
        longOffset: "long",
        longGeneric: "long",
      },
    },
    {
      date: 0,
      timeZone: "+23:59",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("GMT+23:59")],
        shortOffset: "short",
        shortGeneric: "short",
        long: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("GMT+23:59")],
        longOffset: "long",
        longGeneric: "long",
      },
    },
  ],
  "fr": [
    {
      date: 0,
      timeZone: "-23",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("UTC\u{2212}23")],
        shortOffset: "short",
        shortGeneric: "short",
        long: [Hour("01"), Literal(":"), Minute("00"), Literal(" "), TimeZoneName("UTC\u{2212}23:00")],
        longOffset: "long",
        longGeneric: "long",
      },
    },
    {
      date: 0,
      timeZone: "+23:59",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("UTC+23:59")],
        shortOffset: "short",
        shortGeneric: "short",
        long: [Hour("23"), Literal(":"), Minute("59"), Literal(" "), TimeZoneName("UTC+23:59")],
        longOffset: "long",
        longGeneric: "long",
      },
    },
  ],
  "ar": [
    {
      date: 0,
      timeZone: "+13:37",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("١٣"), Literal(":"), Minute("٣٧"), Literal(" "), TimeZoneName("غرينتش+١٣:٣٧")],
        shortOffset: "short",
        shortGeneric: "short",
        long: "short",
        longOffset: "short",
        longGeneric: "short",
      },
    },
  ],
  "zh": [
    {
      date: 0,
      timeZone: "+23:59",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [TimeZoneName("GMT+23:59"), Literal(" "), Hour("23"), Literal(":"), Minute("59")],
        shortOffset: "short",
        shortGeneric: "short",
        long: "short",
        longOffset: "short",
        longGeneric: "short",
      },
    },
  ],
};

for (let [locale, formats] of Object.entries(tests)) {
  for (let {date, 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];
      }
      assertParts(df, date, format);
    }
  }
}

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