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 0000000000..5d889e3478 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/format/temporal-objects-format-with-era.js @@ -0,0 +1,21 @@ +// 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" }); + +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.sameValue(formatter.format(new Temporal.Instant(0n)), + new Date(0).toLocaleString(["en"], { era: "narrow" }), "toLocaleString on an Instant with era option should return the same results as toLocaleString on the same Date with the same options"); 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 0000000000..3a79a6e64c --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/temporal-objects-format-with-era.js @@ -0,0 +1,25 @@ +// 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.formatRange(new Temporal.PlainDate(2025, 11, 4), new Temporal.PlainDate(2025, 11, 5)).startsWith("11"), "formatting a PlainDate should work"); +assert(formatter.formatRange(new Temporal.PlainYearMonth(2025, 11, "gregory"), new Temporal.PlainYearMonth(2025, 12, "gregory")).startsWith("11"), "formatting a PlainYearMonth should work"); +assert(formatter.formatRange(new Temporal.PlainMonthDay(11, 4, "gregory"), new Temporal.PlainMonthDay(11, 14, "gregory")).startsWith("11"), "formatting a PlainMonthDay should work"); +assert(formatter.formatRange(new Temporal.PlainTime(14, 46), new Temporal.PlainTime(17, 46)).startsWith("2"), "formatting a PlainTime should work"); +assert(formatter.formatRange(new Temporal.PlainDateTime(2025, 11, 4, 14, 16, 0, 0, 0, 0, "gregory"), new Temporal.PlainDateTime(2025, 11, 15, 14, 47, 0, 0, 0, 0, "gregory")).startsWith("11"), "formatting a PlainDateTime should work"); + +// For instants, check the output of formatRange on the equivalent Dates and then check that this is a prefix +// of the output of formatRange on the Instants, because the time zone of the host might affect the output +const dateResult = formatter.formatRange(new Date(0), new Date(1)); +assert(formatter.formatRange(new Temporal.Instant(0n), new Temporal.Instant(1000000000n)).startsWith(dateResult), + "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 0000000000..c6cead9e69 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-objects-format-with-era.js @@ -0,0 +1,28 @@ +// 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" }); + +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 , "gregory"), new Temporal.PlainDate(2025, 11, 5, "gregory"))), "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, 16, 0, 0, 0, 0, "gregory"), new Temporal.PlainDateTime(2025, 11, 15, 14, 47, 0, 0, 0, 0, "gregory"))), "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 0000000000..cec677c1d8 --- /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" }); + +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"); diff --git a/test/intl402/Temporal/Instant/prototype/toLocaleString/era.js b/test/intl402/Temporal/Instant/prototype/toLocaleString/era.js new file mode 100644 index 0000000000..4978a0441d --- /dev/null +++ b/test/intl402/Temporal/Instant/prototype/toLocaleString/era.js @@ -0,0 +1,17 @@ +// 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); + +const instantResult = instant.toLocaleString("en", { era: "narrow" }); +const dateResult = new Date(0).toLocaleString(["en"], { era: "narrow" }); +assert.sameValue(instantResult, dateResult, "toLocaleString on an Instant with era option should return the same results as toLocaleString on the same Date with the same options"); diff --git a/test/intl402/Temporal/PlainDate/prototype/toLocaleString/era.js b/test/intl402/Temporal/PlainDate/prototype/toLocaleString/era.js new file mode 100644 index 0000000000..d6ab1e8fd9 --- /dev/null +++ b/test/intl402/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/intl402/Temporal/PlainDateTime/prototype/toLocaleString/era.js b/test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/era.js new file mode 100644 index 0000000000..eace04aed8 --- /dev/null +++ b/test/intl402/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/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/era.js b/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/era.js new file mode 100644 index 0000000000..d4f51b418a --- /dev/null +++ b/test/intl402/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/intl402/Temporal/PlainTime/prototype/toLocaleString/era.js b/test/intl402/Temporal/PlainTime/prototype/toLocaleString/era.js new file mode 100644 index 0000000000..7f5b59fa3b --- /dev/null +++ b/test/intl402/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/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/era.js b/test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/era.js new file mode 100644 index 0000000000..7fe4beece1 --- /dev/null +++ b/test/intl402/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/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/era.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/era.js new file mode 100644 index 0000000000..1495c9b62a --- /dev/null +++ b/test/intl402/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");