summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js
blob: 203ba03766db5f1b8a72405fb7468f42d6daaf62 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
// |reftest| skip-if(!this.hasOwnProperty("Intl"))

// Tests using various locales to cover all day period types:
// "midnight", "noon", "morning1", "morning2", "afternoon1", "afternoon2",
// "evening1", "evening2", "night1", "night2".

const tests = [
  {
      // ICU doesn't support "midnight" and instead uses "night1" resp. "night2".
      // ICU bug: https://unicode-org.atlassian.net/projects/ICU/issues/ICU-12278
      date: new Date("2019-01-01T00:00:00"),
      locales: {
          en: { narrow: "at night", short: "at night", long: "at night" },
          de: { narrow: "nachts", short: "nachts", long: "nachts" },
          th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" },
          ja: { narrow: "夜中", short: "夜中", long: "夜中" },
      }
  },
  {
      date: new Date("2019-01-01T03:00:00"),
      locales: {
          en: { narrow: "at night", short: "at night", long: "at night" },
          de: { narrow: "nachts", short: "nachts", long: "nachts" },
          th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" },
          ja: { narrow: "夜中", short: "夜中", long: "夜中" },
      }
  },
  {
      date: new Date("2019-01-01T04:00:00"),
      locales: {
          en: { narrow: "at night", short: "at night", long: "at night" },
          de: { narrow: "nachts", short: "nachts", long: "nachts" },
          th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" },
          ja: { narrow: "朝", short: "朝", long: "朝" },
      }
  },
  {
      date: new Date("2019-01-01T05:00:00"),
      locales: {
          en: { narrow: "at night", short: "at night", long: "at night" },
          de: { narrow: "morgens", short: "morgens", long: "morgens" },
          th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" },
          ja: { narrow: "朝", short: "朝", long: "朝" },
      }
  },
  {
      date: new Date("2019-01-01T06:00:00"),
      locales: {
          en: { narrow: "in the morning", short: "in the morning", long: "in the morning" },
          de: { narrow: "morgens", short: "morgens", long: "morgens" },
          th: { narrow: "เช้า", short: "ในตอนเช้า", long: "ในตอนเช้า" },
          ja: { narrow: "朝", short: "朝", long: "朝" },
      }
  },
  {
      date: new Date("2019-01-01T10:00:00"),
      locales: {
          en: { narrow: "in the morning", short: "in the morning", long: "in the morning" },
          de: { narrow: "vorm.", short: "vorm.", long: "vormittags" },
          th: { narrow: "เช้า", short: "ในตอนเช้า", long: "ในตอนเช้า" },
          ja: { narrow: "朝", short: "朝", long: "朝" },
      }
  },
  {
      date: new Date("2019-01-01T12:00:00"),
      locales: {
          en: { narrow: "n", short: "noon", long: "noon" },
          de: { narrow: "mittags", short: "mittags", long: "mittags" },
          th: { narrow: "เที่ยง", short: "เที่ยง", long: "เที่ยง" },
          ja: { narrow: "正午", short: "正午", long: "正午" },
      }
  },
  {
      date: new Date("2019-01-01T13:00:00"),
      locales: {
          en: { narrow: "in the afternoon", short: "in the afternoon", long: "in the afternoon" },
          de: { narrow: "nachm.", short: "nachm.", long: "nachmittags" },
          th: { narrow: "บ่าย", short: "บ่าย", long: "บ่าย" },
          ja: { narrow: "昼", short: "昼", long: "昼" },
      }
  },
  {
      date: new Date("2019-01-01T15:00:00"),
      locales: {
          en: { narrow: "in the afternoon", short: "in the afternoon", long: "in the afternoon" },
          de: { narrow: "nachm.", short: "nachm.", long: "nachmittags" },
          th: { narrow: "บ่าย", short: "บ่าย", long: "บ่าย" },
          ja: { narrow: "昼", short: "昼", long: "昼" },
      }
  },
  {
      date: new Date("2019-01-01T16:00:00"),
      locales: {
          en: { narrow: "in the afternoon", short: "in the afternoon", long: "in the afternoon" },
          de: { narrow: "nachm.", short: "nachm.", long: "nachmittags" },
          th: { narrow: "เย็น", short: "ในตอนเย็น", long: "ในตอนเย็น" },
          ja: { narrow: "夕方", short: "夕方", long: "夕方" },
      }
  },
  {
      date: new Date("2019-01-01T18:00:00"),
      locales: {
          en: { narrow: "in the evening", short: "in the evening", long: "in the evening" },
          de: { narrow: "abends", short: "abends", long: "abends" },
          th: { narrow: "ค่ำ", short: "ค่ำ", long: "ค่ำ" },
          ja: { narrow: "夕方", short: "夕方", long: "夕方" },
      }
  },
  {
      date: new Date("2019-01-01T19:00:00"),
      locales: {
          en: { narrow: "in the evening", short: "in the evening", long: "in the evening" },
          de: { narrow: "abends", short: "abends", long: "abends" },
          th: { narrow: "ค่ำ", short: "ค่ำ", long: "ค่ำ" },
          ja: { narrow: "夜", short: "夜", long: "夜" },
      }
  },
  {
      date: new Date("2019-01-01T21:00:00"),
      locales: {
          en: { narrow: "at night", short: "at night", long: "at night" },
          de: { narrow: "abends", short: "abends", long: "abends" },
          th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" },
          ja: { narrow: "夜", short: "夜", long: "夜" },
      }
  },
  {
      date: new Date("2019-01-01T22:00:00"),
      locales: {
          en: { narrow: "at night", short: "at night", long: "at night" },
          de: { narrow: "abends", short: "abends", long: "abends" },
          th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" },
          ja: { narrow: "夜", short: "夜", long: "夜" },
      }
  },
  {
      date: new Date("2019-01-01T23:00:00"),
      locales: {
          en: { narrow: "at night", short: "at night", long: "at night" },
          de: { narrow: "abends", short: "abends", long: "abends" },
          th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" },
          ja: { narrow: "夜中", short: "夜中", long: "夜中" },
      }
  },
];

for (let {date, locales} of tests) {
    for (let [locale, formats] of Object.entries(locales)) {
        for (let [dayPeriod, expected] of Object.entries(formats)) {
            let dtf = new Intl.DateTimeFormat(locale, {dayPeriod});

            assertEq(dtf.format(date), expected,
                     `locale=${locale}, date=${date}, dayPeriod=${dayPeriod}`);
            assertDeepEq(dtf.formatToParts(date), [{type: "dayPeriod", value: expected}]);
        }
    }
}

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