diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/tests/non262/Intl/DateTimeFormat/field-widths.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | js/src/tests/non262/Intl/DateTimeFormat/field-widths.js | 225 |
1 files changed, 225 insertions, 0 deletions
diff --git a/js/src/tests/non262/Intl/DateTimeFormat/field-widths.js b/js/src/tests/non262/Intl/DateTimeFormat/field-widths.js new file mode 100644 index 0000000000..789d0fdaa6 --- /dev/null +++ b/js/src/tests/non262/Intl/DateTimeFormat/field-widths.js @@ -0,0 +1,225 @@ +// |reftest| skip-if(!this.hasOwnProperty("Intl")) + +const date = new Date(Date.UTC(2021, 1-1, 2, 3, 4, 5, 678)); + +const tests = [ + // Standalone 'hour' field. + { + options: { + hour: "numeric", + }, + locales: { + "en": "3 AM", + "de": "03 Uhr", + }, + }, + { + options: { + hour: "2-digit", + }, + locales: { + "en": "03 AM", + "de": "03 Uhr", + }, + }, + + // Standalone 'minute' field. + { + options: { + minute: "numeric", + }, + locales: { + "en": "4", + "de": "4", + }, + }, + { + options: { + minute: "2-digit", + }, + locales: { + "en": "04", + "de": "04", + }, + }, + + // Standalone 'second' field. + { + options: { + second: "numeric", + }, + locales: { + "en": "5", + "de": "5", + }, + }, + { + options: { + second: "2-digit", + }, + locales: { + "en": "05", + "de": "05", + }, + }, + + // 'hour' and 'minute' fields with all possible field width combinations. + { + options: { + hour: "numeric", + minute: "numeric", + }, + locales: { + "en": "3:04 AM", + "de": "03:04", + }, + }, + { + options: { + hour: "numeric", + minute: "2-digit", + }, + locales: { + "en": "3:04 AM", + "de": "03:04", + }, + }, + { + options: { + hour: "2-digit", + minute: "numeric", + }, + locales: { + "en": "03:04 AM", + "de": "03:04", + }, + }, + { + options: { + hour: "2-digit", + minute: "2-digit", + }, + locales: { + "en": "03:04 AM", + "de": "03:04", + }, + }, + + // 'minute' and 'second' fields with all possible field width combinations. + { + options: { + minute: "numeric", + second: "numeric", + }, + locales: { + "en": "04:05", + "de": "04:05", + }, + }, + { + options: { + minute: "numeric", + second: "2-digit", + }, + locales: { + "en": "04:05", + "de": "04:05", + }, + }, + { + options: { + minute: "2-digit", + second: "numeric", + }, + locales: { + "en": "04:05", + "de": "04:05", + }, + }, + { + options: { + minute: "2-digit", + second: "2-digit", + }, + locales: { + "en": "04:05", + "de": "04:05", + }, + }, + + // Test 'hour' and 'minute' with 'hourCycle=h12'. + { + options: { + hour: "numeric", + minute: "numeric", + hourCycle: "h12", + }, + locales: { + "en": "3:04 AM", + "de": "3:04 AM", + }, + }, + { + options: { + hour: "2-digit", + minute: "2-digit", + hourCycle: "h12", + }, + locales: { + "en": "03:04 AM", + "de": "03:04 AM", + }, + }, + + // Test 'hour' and 'minute' with 'hourCycle=h23'. + { + options: { + hour: "numeric", + minute: "numeric", + hourCycle: "h23", + }, + locales: { + "en": "03:04", + "de": "03:04", + }, + }, + { + options: { + hour: "2-digit", + minute: "2-digit", + hourCycle: "h23", + }, + locales: { + "en": "03:04", + "de": "03:04", + }, + }, +]; + +for (let {options, locales} of tests) { + for (let [locale, expected] of Object.entries(locales)) { + let dtf = new Intl.DateTimeFormat(locale, {timeZone: "UTC", ...options}); + assertEq(dtf.format(date), expected); + } +} + +const toLocaleTests = { + "en": "1/2/2021, 3:04:05 AM", + "de": "2.1.2021, 03:04:05", +}; + +for (let [locale, expected] of Object.entries(toLocaleTests)) { + assertEq(date.toLocaleString(locale, {timeZone: "UTC"}), expected); +} + +const toLocaleTimeTests = { + "en": "3:04:05 AM", + "de": "03:04:05", +}; + +for (let [locale, expected] of Object.entries(toLocaleTimeTests)) { + assertEq(date.toLocaleTimeString(locale, {timeZone: "UTC"}), expected); +} + +if (typeof reportCompare === "function") + reportCompare(0, 0, "ok"); |