summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js')
-rw-r--r--js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js b/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js
new file mode 100644
index 0000000000..6bfbf94df3
--- /dev/null
+++ b/js/src/tests/non262/Intl/DateTimeFormat/day-period-hour-cycle.js
@@ -0,0 +1,102 @@
+// |reftest| skip-if(!this.hasOwnProperty("Intl"))
+
+const {
+ Year, Month, Day, DayPeriod, Hour, Minute, Literal
+} = DateTimeFormatParts;
+
+// If the locale defaults to a 24-hour-cycle, the "dayPeriod" option is ignored if an "hour" option
+// is also present, unless the hour-cycle is manually set to a 12-hour-cycle.
+
+const tests = [
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", hour: "numeric", },
+ locales: {
+ en: [Hour("12"), Literal(" "), DayPeriod("noon")],
+ de: [Hour("12"), Literal(" Uhr")],
+ },
+ },
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", hour: "numeric", hour12: true },
+ locales: {
+ en: [Hour("12"), Literal(" "), DayPeriod("noon")],
+ de: [Hour("12"), Literal(" "), DayPeriod("mittags")],
+ },
+ },
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", hour: "numeric", hour12: false },
+ locales: {
+ en: [Hour("12")],
+ de: [Hour("12"), Literal(" Uhr")],
+ },
+ },
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", hour: "numeric", hourCycle: "h12" },
+ locales: {
+ en: [Hour("12"), Literal(" "), DayPeriod("noon")],
+ de: [Hour("12"), Literal(" "), DayPeriod("mittags")],
+ },
+ },
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", hour: "numeric", hourCycle: "h11" },
+ locales: {
+ en: [Hour("0"), Literal(" "), DayPeriod("noon")],
+ de: [Hour("0"), Literal(" "), DayPeriod("mittags")],
+ },
+ },
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", hour: "numeric", hourCycle: "h23" },
+ locales: {
+ en: [Hour("12")],
+ de: [Hour("12"), Literal(" Uhr")],
+ },
+ },
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", hour: "numeric", hourCycle: "h24" },
+ locales: {
+ en: [Hour("12")],
+ de: [Hour("12"), Literal(" Uhr")],
+ },
+ },
+
+ // The default hour-cycle is irrelevant when an "hour" option isn't present.
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", day: "numeric", month: "numeric", year: "numeric" },
+ locales: {
+ en: [Month("1"), Literal("/"), Day("1"), Literal("/"), Year("2019"), Literal(", "), DayPeriod("noon")],
+ de: [Day("1"), Literal("."), Month("1"), Literal("."), Year("2019"), Literal(", "), DayPeriod("mittags")],
+ },
+ },
+
+ // ICU replacement pattern for missing <appendItem> entries in CLDR.
+ {
+ date: new Date("2019-01-01T12:00:00"),
+ options: { dayPeriod: "short", minute: "numeric" },
+ locales: {
+ en: [Minute("0"), Literal(" (AM/PM: "), DayPeriod("noon"), Literal(")")],
+ de: [Minute("0"), Literal(" (Tageshälfte: "), DayPeriod("mittags"), Literal(")")],
+ },
+ },
+];
+
+for (let {date, options, locales} of tests) {
+ for (let [locale, parts] of Object.entries(locales)) {
+ let dtf = new Intl.DateTimeFormat(locale, options);
+
+ assertEq(dtf.format(date), parts.map(({value}) => value).join(""),
+ `locale=${locale}, date=${date}, options=${JSON.stringify(options)}`);
+
+ assertDeepEq(dtf.formatToParts(date), parts,
+ `locale=${locale}, date=${date}, options=${JSON.stringify(options)}`);
+ }
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(0, 0, "ok");