diff --git a/test/built-ins/Temporal/Instant/prototype/toLocaleString/era.js b/test/built-ins/Temporal/Instant/prototype/toLocaleString/era.js new file mode 100644 index 00000000000..6daee3deec3 --- /dev/null +++ b/test/built-ins/Temporal/Instant/prototype/toLocaleString/era.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L.. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.instant.prototype.tolocalestring +description: > + If era option and no other options are provided to toLocaleString, + Instant should be foramtted with default options +features: [Temporal] +locale: [en] +---*/ + +const instant = new Temporal.Instant(0n); + +assert(instant.toLocaleString("en", { era: "narrow", timeZone: "UTC" }).startsWith("1"), "toLocaleString on an Instant with era option should work"); diff --git a/test/built-ins/Temporal/PlainDate/prototype/toLocaleString/era.js b/test/built-ins/Temporal/PlainDate/prototype/toLocaleString/era.js new file mode 100644 index 00000000000..d6ab1e8fd96 --- /dev/null +++ b/test/built-ins/Temporal/PlainDate/prototype/toLocaleString/era.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L.. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindate.prototype.tolocalestring +description: > + If era option and no other options are provided to toLocaleString, + PlainDate should be foramtted with default options +features: [Temporal] +locale: [en] +---*/ + +const date = new Temporal.PlainDate(2000, 5, 2, "gregory"); + +assert(date.toLocaleString("en", { era: "narrow" }).startsWith("5"), "toLocaleString on a PlainDate with era option should work"); diff --git a/test/built-ins/Temporal/PlainDateTime/prototype/toLocaleString/era.js b/test/built-ins/Temporal/PlainDateTime/prototype/toLocaleString/era.js new file mode 100644 index 00000000000..eace04aed87 --- /dev/null +++ b/test/built-ins/Temporal/PlainDateTime/prototype/toLocaleString/era.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L.. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaindatetime.prototype.tolocalestring +description: > + If era option and no other options are provided to toLocaleString, + PlainDateTime should be foramtted with default options +features: [Temporal] +locale: [en] +---*/ + +date = new Temporal.PlainDateTime(2000, 5, 2, 14, 46, 0, 0, 0, 0, "gregory"); + +assert(date.toLocaleString("en", { era: "narrow" }).startsWith("5"), "toLocaleString on a PlainDateTime with era option should work"); diff --git a/test/built-ins/Temporal/PlainMonthDay/prototype/toLocaleString/era.js b/test/built-ins/Temporal/PlainMonthDay/prototype/toLocaleString/era.js new file mode 100644 index 00000000000..d4f51b418ab --- /dev/null +++ b/test/built-ins/Temporal/PlainMonthDay/prototype/toLocaleString/era.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L.. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainmonthday.prototype.tolocalestring +description: > + If era option and no other options are provided to toLocaleString, + PlainMonthDay should be foramtted with default options +features: [Temporal] +locale: [en] +---*/ + +const date = new Temporal.PlainMonthDay(5, 2, "gregory"); + +assert(date.toLocaleString("en", { era: "narrow" }).startsWith("5"), "toLocaleString on a PlainMonthDay with era option should work"); diff --git a/test/built-ins/Temporal/PlainTime/prototype/toLocaleString/era.js b/test/built-ins/Temporal/PlainTime/prototype/toLocaleString/era.js new file mode 100644 index 00000000000..7f5b59fa3b4 --- /dev/null +++ b/test/built-ins/Temporal/PlainTime/prototype/toLocaleString/era.js @@ -0,0 +1,18 @@ +// Copyright (C) 2025 Igalia, S.L.. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plaintime.prototype.tolocalestring +description: > + If era option and no other options are provided to toLocaleString, + PlainTime should be foramtted with default options +features: [Temporal] +locale: [en] +---*/ + +const date = new Temporal.PlainTime(14, 46); + +const result = date.toLocaleString("en", { era: "narrow" }); + +assert(result.startsWith("2"), "toLocaleString on a PlainTime with era option should work"); +assert(!result.includes("A"), "era should be ignored when formatting a PlainTime"); diff --git a/test/built-ins/Temporal/PlainYearMonth/prototype/toLocaleString/era.js b/test/built-ins/Temporal/PlainYearMonth/prototype/toLocaleString/era.js new file mode 100644 index 00000000000..7fe4beece1b --- /dev/null +++ b/test/built-ins/Temporal/PlainYearMonth/prototype/toLocaleString/era.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L.. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.plainyearmonth.prototype.tolocalestring +description: > + If era option and no other options are provided to toLocaleString, + PlainYearMonth should be foramtted with default options +features: [Temporal] +locale: [en] +---*/ + +const date = new Temporal.PlainYearMonth(2000, 5, "gregory"); + +assert(date.toLocaleString("en", { era: "narrow" }).startsWith("5"), "toLocaleString on a PlainYearMonth with era option should work"); diff --git a/test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/era.js b/test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/era.js new file mode 100644 index 00000000000..1495c9b62a3 --- /dev/null +++ b/test/built-ins/Temporal/ZonedDateTime/prototype/toLocaleString/era.js @@ -0,0 +1,15 @@ +// Copyright (C) 2025 Igalia, S.L.. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-temporal.zoneddatetime.prototype.tolocalestring +description: > + If era option and no other options are provided to toLocaleString, + ZonedDateTime should be foramtted with default options +features: [Temporal] +locale: [en] +---*/ + +const zdt = new Temporal.ZonedDateTime(0n, "UTC"); + +assert(zdt.toLocaleString("en", { era: "narrow" }).startsWith("1"), "toLocaleString on a ZonedDateTime with era option should work"); diff --git a/test/intl402/DateTimeFormat/prototype/format/temporal-objects-format-with-era.js b/test/intl402/DateTimeFormat/prototype/format/temporal-objects-format-with-era.js new file mode 100644 index 00000000000..be3ebcd96c1 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/format/temporal-objects-format-with-era.js @@ -0,0 +1,20 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-datetime-format-functions +description: > + If era option and no other options are provided to DateTimeFormat constructor, + objects should be formatted with default options +features: [Temporal] +locale: [en] +---*/ + +const formatter = new Intl.DateTimeFormat(["en"], { era: "narrow", timeZone: "UTC" }); + +assert(formatter.format(new Temporal.PlainDate(2025, 11, 4)).startsWith("11"), "formatting a PlainDate should work"); +assert(formatter.format(new Temporal.PlainYearMonth(2025, 11, "gregory")).startsWith("11"), "formatting a PlainYearMonth should work"); +assert(formatter.format(new Temporal.PlainMonthDay(11, 4, "gregory")).startsWith("11"), "formatting a PlainMonthDay should work"); +assert(formatter.format(new Temporal.PlainTime(14, 46)).startsWith("2"), "formatting a PlainTime should work"); +assert(formatter.format(new Temporal.PlainDateTime(2025, 11, 4, 14, 46)).startsWith("11"), "formatting a PlainDateTime should work"); +assert(formatter.format(new Temporal.Instant(0n)).startsWith("1"), "formatting an Instant should work"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/temporal-objects-format-with-era.js b/test/intl402/DateTimeFormat/prototype/formatRange/temporal-objects-format-with-era.js new file mode 100644 index 00000000000..be3ebcd96c1 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/temporal-objects-format-with-era.js @@ -0,0 +1,20 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-datetime-format-functions +description: > + If era option and no other options are provided to DateTimeFormat constructor, + objects should be formatted with default options +features: [Temporal] +locale: [en] +---*/ + +const formatter = new Intl.DateTimeFormat(["en"], { era: "narrow", timeZone: "UTC" }); + +assert(formatter.format(new Temporal.PlainDate(2025, 11, 4)).startsWith("11"), "formatting a PlainDate should work"); +assert(formatter.format(new Temporal.PlainYearMonth(2025, 11, "gregory")).startsWith("11"), "formatting a PlainYearMonth should work"); +assert(formatter.format(new Temporal.PlainMonthDay(11, 4, "gregory")).startsWith("11"), "formatting a PlainMonthDay should work"); +assert(formatter.format(new Temporal.PlainTime(14, 46)).startsWith("2"), "formatting a PlainTime should work"); +assert(formatter.format(new Temporal.PlainDateTime(2025, 11, 4, 14, 46)).startsWith("11"), "formatting a PlainDateTime should work"); +assert(formatter.format(new Temporal.Instant(0n)).startsWith("1"), "formatting an Instant should work"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-objects-format-with-era.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-objects-format-with-era.js new file mode 100644 index 00000000000..15762a93c4b --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-objects-format-with-era.js @@ -0,0 +1,29 @@ +// Copyright (C) 2024 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-datetime-format-functions +description: > + If era option and no other options are provided to DateTimeFormat constructor, + objects should be formatted with default options +features: [Temporal] +locale: [en] +---*/ + +const formatter = new Intl.DateTimeFormat(["en"], { era: "narrow", timeZone: "UTC" }); + +function checkEra(parts) { + for (let part of parts) { + if (part.type === 'era' && part.value.startsWith('A')) + return true; + } + return false; +} + +assert(checkEra(formatter.formatRangeToParts(new Temporal.PlainDate(2025, 11, 4), new Temporal.PlainDate(2025, 11, 5))), "formatting a PlainDate should work"); +assert(checkEra(formatter.formatRangeToParts(new Temporal.PlainDate(2025, 11, 4), new Temporal.PlainDate(2025, 11, 5))), "formatting a PlainDate should work"); +assert(checkEra(formatter.formatRangeToParts(new Temporal.PlainYearMonth(2025, 11, "gregory"), new Temporal.PlainYearMonth(2025, 12, "gregory"))), "formatting a PlainYearMonth should work"); +assert(checkEra(formatter.formatRangeToParts(new Temporal.PlainMonthDay(11, 4, "gregory"), new Temporal.PlainMonthDay(11, 14, "gregory"))), "formatting a PlainMonthDay should work"); +assert(!checkEra(formatter.formatRangeToParts(new Temporal.PlainTime(14, 46), new Temporal.PlainTime(17, 46))), "formatting a PlainTime should work"); +assert(checkEra(formatter.formatRangeToParts(new Temporal.PlainDateTime(2025, 11, 4, 14, 46), new Temporal.PlainDateTime(2025, 11, 15, 14, 47))), "formatting a PlainDateTime should work"); +assert(checkEra(formatter.formatRangeToParts(new Temporal.Instant(0n), new Temporal.Instant(1000000000n))), "formatting an Instant should work"); diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/temporal-objects-format-with-era.js b/test/intl402/DateTimeFormat/prototype/formatToParts/temporal-objects-format-with-era.js new file mode 100644 index 00000000000..8ae3eb48b13 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatToParts/temporal-objects-format-with-era.js @@ -0,0 +1,28 @@ +// Copyright (C) 2025 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-datetime-format-functions +description: > + If era option and no other options are provided to DateTimeFormat constructor, + objects should be formatted with default options +features: [Temporal] +locale: [en] +---*/ + +const formatter = new Intl.DateTimeFormat(["en"], { era: "narrow", timeZone: "UTC" }); + +function checkEra(parts) { + for (let part of parts) { + if (part.type === 'era' && part.value.startsWith('A')) + return true; + } + return false; +} + +assert(checkEra(formatter.formatToParts(new Temporal.PlainDate(2025, 11, 4))), "formatting a PlainDate should work"); +assert(checkEra(formatter.formatToParts(new Temporal.PlainYearMonth(2025, 11, "gregory"))), "formatting a PlainYearMonth should work"); +assert(checkEra(formatter.formatToParts(new Temporal.PlainMonthDay(11, 4, "gregory"))), "formatting a PlainMonthDay should work"); +assert(!checkEra(formatter.formatToParts(new Temporal.PlainTime(14, 46))), "formatting a PlainTime should work"); +assert(checkEra(formatter.formatToParts(new Temporal.PlainDateTime(2025, 11, 4, 14, 46))), "formatting a PlainDateTime should work"); +assert(checkEra(formatter.formatToParts(new Temporal.Instant(0n))), "formatting an Instant should work");