summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js')
-rw-r--r--js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js160
1 files changed, 160 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js b/js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js
new file mode 100644
index 0000000000..203ba03766
--- /dev/null
+++ b/js/src/tests/non262/Intl/DateTimeFormat/day-period-standalone.js
@@ -0,0 +1,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");