| 1 |
// |reftest| skip-if(!this.hasOwnProperty("Intl")) |
| 2 |
|
| 3 |
// Tests using various locales to cover all day period types: |
| 4 |
// "midnight", "noon", "morning1", "morning2", "afternoon1", "afternoon2", |
| 5 |
// "evening1", "evening2", "night1", "night2". |
| 6 |
|
| 7 |
const tests = [ |
| 8 |
{ |
| 9 |
// ICU doesn't support "midnight" and instead uses "night1" resp. "night2". |
| 10 |
// ICU bug: https://unicode-org.atlassian.net/projects/ICU/issues/ICU-12278 |
| 11 |
date: new Date("2019-01-01T00:00:00"), |
| 12 |
locales: { |
| 13 |
en: { narrow: "in the morning", short: "in the morning", long: "in the morning" }, |
| 14 |
de: { narrow: "nachts", short: "nachts", long: "nachts" }, |
| 15 |
th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" }, |
| 16 |
ja: { narrow: "夜中", short: "夜中", long: "夜中" }, |
| 17 |
} |
| 18 |
}, |
| 19 |
{ |
| 20 |
date: new Date("2019-01-01T03:00:00"), |
| 21 |
locales: { |
| 22 |
en: { narrow: "in the morning", short: "in the morning", long: "in the morning" }, |
| 23 |
de: { narrow: "nachts", short: "nachts", long: "nachts" }, |
| 24 |
th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" }, |
| 25 |
ja: { narrow: "夜中", short: "夜中", long: "夜中" }, |
| 26 |
} |
| 27 |
}, |
| 28 |
{ |
| 29 |
date: new Date("2019-01-01T04:00:00"), |
| 30 |
locales: { |
| 31 |
en: { narrow: "in the morning", short: "in the morning", long: "in the morning" }, |
| 32 |
de: { narrow: "nachts", short: "nachts", long: "nachts" }, |
| 33 |
th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" }, |
| 34 |
ja: { narrow: "朝", short: "朝", long: "朝" }, |
| 35 |
} |
| 36 |
}, |
| 37 |
{ |
| 38 |
date: new Date("2019-01-01T05:00:00"), |
| 39 |
locales: { |
| 40 |
en: { narrow: "in the morning", short: "in the morning", long: "in the morning" }, |
| 41 |
de: { narrow: "morgens", short: "morgens", long: "morgens" }, |
| 42 |
th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" }, |
| 43 |
ja: { narrow: "朝", short: "朝", long: "朝" }, |
| 44 |
} |
| 45 |
}, |
| 46 |
{ |
| 47 |
date: new Date("2019-01-01T06:00:00"), |
| 48 |
locales: { |
| 49 |
en: { narrow: "in the morning", short: "in the morning", long: "in the morning" }, |
| 50 |
de: { narrow: "morgens", short: "morgens", long: "morgens" }, |
| 51 |
th: { narrow: "เช้า", short: "ในตอนเช้า", long: "ในตอนเช้า" }, |
| 52 |
ja: { narrow: "朝", short: "朝", long: "朝" }, |
| 53 |
} |
| 54 |
}, |
| 55 |
{ |
| 56 |
date: new Date("2019-01-01T10:00:00"), |
| 57 |
locales: { |
| 58 |
en: { narrow: "in the morning", short: "in the morning", long: "in the morning" }, |
| 59 |
de: { narrow: "vorm.", short: "vorm.", long: "vormittags" }, |
| 60 |
th: { narrow: "เช้า", short: "ในตอนเช้า", long: "ในตอนเช้า" }, |
| 61 |
ja: { narrow: "朝", short: "朝", long: "朝" }, |
| 62 |
} |
| 63 |
}, |
| 64 |
{ |
| 65 |
date: new Date("2019-01-01T12:00:00"), |
| 66 |
locales: { |
| 67 |
en: { narrow: "n", short: "noon", long: "noon" }, |
| 68 |
de: { narrow: "mittags", short: "mittags", long: "mittags" }, |
| 69 |
th: { narrow: "เที่ยง", short: "เที่ยง", long: "เที่ยง" }, |
| 70 |
ja: { narrow: "正午", short: "正午", long: "正午" }, |
| 71 |
} |
| 72 |
}, |
| 73 |
{ |
| 74 |
date: new Date("2019-01-01T13:00:00"), |
| 75 |
locales: { |
| 76 |
en: { narrow: "in the afternoon", short: "in the afternoon", long: "in the afternoon" }, |
| 77 |
de: { narrow: "nachm.", short: "nachm.", long: "nachmittags" }, |
| 78 |
th: { narrow: "บ่าย", short: "บ่าย", long: "บ่าย" }, |
| 79 |
ja: { narrow: "昼", short: "昼", long: "昼" }, |
| 80 |
} |
| 81 |
}, |
| 82 |
{ |
| 83 |
date: new Date("2019-01-01T15:00:00"), |
| 84 |
locales: { |
| 85 |
en: { narrow: "in the afternoon", short: "in the afternoon", long: "in the afternoon" }, |
| 86 |
de: { narrow: "nachm.", short: "nachm.", long: "nachmittags" }, |
| 87 |
th: { narrow: "บ่าย", short: "บ่าย", long: "บ่าย" }, |
| 88 |
ja: { narrow: "昼", short: "昼", long: "昼" }, |
| 89 |
} |
| 90 |
}, |
| 91 |
{ |
| 92 |
date: new Date("2019-01-01T16:00:00"), |
| 93 |
locales: { |
| 94 |
en: { narrow: "in the afternoon", short: "in the afternoon", long: "in the afternoon" }, |
| 95 |
de: { narrow: "nachm.", short: "nachm.", long: "nachmittags" }, |
| 96 |
th: { narrow: "เย็น", short: "ในตอนเย็น", long: "ในตอนเย็น" }, |
| 97 |
ja: { narrow: "夕方", short: "夕方", long: "夕方" }, |
| 98 |
} |
| 99 |
}, |
| 100 |
{ |
| 101 |
date: new Date("2019-01-01T18:00:00"), |
| 102 |
locales: { |
| 103 |
en: { narrow: "in the evening", short: "in the evening", long: "in the evening" }, |
| 104 |
de: { narrow: "abends", short: "abends", long: "abends" }, |
| 105 |
th: { narrow: "ค่ำ", short: "ค่ำ", long: "ค่ำ" }, |
| 106 |
ja: { narrow: "夕方", short: "夕方", long: "夕方" }, |
| 107 |
} |
| 108 |
}, |
| 109 |
{ |
| 110 |
date: new Date("2019-01-01T19:00:00"), |
| 111 |
locales: { |
| 112 |
en: { narrow: "in the evening", short: "in the evening", long: "in the evening" }, |
| 113 |
de: { narrow: "abends", short: "abends", long: "abends" }, |
| 114 |
th: { narrow: "ค่ำ", short: "ค่ำ", long: "ค่ำ" }, |
| 115 |
ja: { narrow: "夜", short: "夜", long: "夜" }, |
| 116 |
} |
| 117 |
}, |
| 118 |
{ |
| 119 |
date: new Date("2019-01-01T21:00:00"), |
| 120 |
locales: { |
| 121 |
en: { narrow: "at night", short: "at night", long: "at night" }, |
| 122 |
de: { narrow: "abends", short: "abends", long: "abends" }, |
| 123 |
th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" }, |
| 124 |
ja: { narrow: "夜", short: "夜", long: "夜" }, |
| 125 |
} |
| 126 |
}, |
| 127 |
{ |
| 128 |
date: new Date("2019-01-01T22:00:00"), |
| 129 |
locales: { |
| 130 |
en: { narrow: "at night", short: "at night", long: "at night" }, |
| 131 |
de: { narrow: "abends", short: "abends", long: "abends" }, |
| 132 |
th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" }, |
| 133 |
ja: { narrow: "夜", short: "夜", long: "夜" }, |
| 134 |
} |
| 135 |
}, |
| 136 |
{ |
| 137 |
date: new Date("2019-01-01T23:00:00"), |
| 138 |
locales: { |
| 139 |
en: { narrow: "at night", short: "at night", long: "at night" }, |
| 140 |
de: { narrow: "abends", short: "abends", long: "abends" }, |
| 141 |
th: { narrow: "กลางคืน", short: "กลางคืน", long: "กลางคืน" }, |
| 142 |
ja: { narrow: "夜中", short: "夜中", long: "夜中" }, |
| 143 |
} |
| 144 |
}, |
| 145 |
]; |
| 146 |
|
| 147 |
for (let {date, locales} of tests) { |
| 148 |
for (let [locale, formats] of Object.entries(locales)) { |
| 149 |
for (let [dayPeriod, expected] of Object.entries(formats)) { |
| 150 |
let dtf = new Intl.DateTimeFormat(locale, {dayPeriod}); |
| 151 |
|
| 152 |
assertEq(dtf.format(date), expected, |
| 153 |
`locale=${locale}, date=${date}, dayPeriod=${dayPeriod}`); |
| 154 |
assertDeepEq(dtf.formatToParts(date), [{type: "dayPeriod", value: expected}]); |
| 155 |
} |
| 156 |
} |
| 157 |
} |
| 158 |
|
| 159 |
if (typeof reportCompare === "function") |
| 160 |
reportCompare(0, 0, "ok"); |