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

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: "+00",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("GMT")],
        shortOffset: "short",
        shortGeneric: "short",
        long: [Hour("00"), Literal(":"), Minute("00"), Literal(" – "), Hour("00"), Literal(":"), Minute("02"), Literal(" "), TimeZoneName("Greenwich Mean Time")],
        longOffset: "short",
        longGeneric: "long",
      },
    },
    {
      start: 0,
      end: minutes(2),
      timeZone: "-20:01",
      options: {hour: "numeric", minute: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("03"), Literal(":"), Minute("59"), Literal(" – "), Hour("04"), Literal(":"), Minute("01"), Literal(" "), TimeZoneName("GMT-20:01")],
        shortOffset: "short",
        shortGeneric: "short",
        long: "short",
        longOffset: "short",
        longGeneric: "short",
      },
    },
  ],
  "fr": [
    {
      start: 0,
      end: hours(2),
      timeZone: "+17",
      options: {hour: "numeric", hour12: false},
      timeZoneNames: {
        short: [Hour("17"), Literal(" – "), Hour("19"), Literal(" "), TimeZoneName("UTC+17")],
        shortOffset: "short",
        shortGeneric: "short",
        long: [Hour("17"), Literal(" – "), Hour("19"), Literal(" "), TimeZoneName("UTC+17:00")],
        longOffset: "long",
        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");