diff --git a/test/intl402/Temporal/PlainDate/prototype/toLocaleString/calendar-mismatch.js b/test/intl402/Temporal/PlainDate/prototype/toLocaleString/calendar-mismatch.js new file mode 100644 index 0000000000..acf971320b --- /dev/null +++ b/test/intl402/Temporal/PlainDate/prototype/toLocaleString/calendar-mismatch.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 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: Calendar must match the locale calendar if not "iso8601" +features: [Temporal, Intl-enumeration] +---*/ + +const localeCalendar = new Intl.DateTimeFormat().resolvedOptions().calendar; +assert.notSameValue(localeCalendar, "iso8601", "no locale has the ISO calendar"); + +const sameCalendarInstance = new Temporal.PlainDate(2000, 5, 2, localeCalendar); +const result = sameCalendarInstance.toLocaleString(); +assert.sameValue(typeof result, "string", "toLocaleString() succeeds when instance has the same calendar as locale"); + +const isoInstance = new Temporal.PlainDate(2000, 5, 2, "iso8601"); +assert.sameValue(isoInstance.toLocaleString(), result, "toLocaleString() succeeds when instance has the ISO calendar") + +// Pick a different calendar that is not ISO and not the locale's calendar +const calendars = new Set(Intl.supportedValuesOf("calendar")); +calendars.delete("iso8601"); +calendars.delete(localeCalendar); +const differentCalendar = calendars.values().next().value; + +const differentCalendarInstance = new Temporal.PlainDate(2000, 5, 2, differentCalendar); +assert.throws(RangeError, () => differentCalendarInstance.toLocaleString(), "calendar mismatch"); diff --git a/test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js b/test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js new file mode 100644 index 0000000000..d57a32bcf3 --- /dev/null +++ b/test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 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: Calendar must match the locale calendar if not "iso8601" +features: [Temporal, Intl-enumeration] +---*/ + +const localeCalendar = new Intl.DateTimeFormat().resolvedOptions().calendar; +assert.notSameValue(localeCalendar, "iso8601", "no locale has the ISO calendar"); + +const sameCalendarInstance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, localeCalendar); +const result = sameCalendarInstance.toLocaleString(); +assert.sameValue(typeof result, "string", "toLocaleString() succeeds when instance has the same calendar as locale"); + +const isoInstance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, "iso8601"); +assert.sameValue(isoInstance.toLocaleString(), result, "toLocaleString() succeeds when instance has the ISO calendar") + +// Pick a different calendar that is not ISO and not the locale's calendar +const calendars = new Set(Intl.supportedValuesOf("calendar")); +calendars.delete("iso8601"); +calendars.delete(localeCalendar); +const differentCalendar = calendars.values().next().value; + +const differentCalendarInstance = new Temporal.PlainDateTime(2000, 5, 2, 12, 34, 56, 987, 654, 321, differentCalendar); +assert.throws(RangeError, () => differentCalendarInstance.toLocaleString(), "calendar mismatch"); diff --git a/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js b/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js new file mode 100644 index 0000000000..40de8ba551 --- /dev/null +++ b/test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 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: Calendar must match the locale calendar if not "iso8601" +features: [Temporal, Intl-enumeration] +---*/ + +const localeCalendar = new Intl.DateTimeFormat().resolvedOptions().calendar; +assert.notSameValue(localeCalendar, "iso8601", "no locale has the ISO calendar"); + +const sameCalendarInstance = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: localeCalendar }); +const result = sameCalendarInstance.toLocaleString(); +assert.sameValue(typeof result, "string", "toLocaleString() succeeds when instance has the same calendar as locale"); + +// Pick a different calendar that is not ISO and not the locale's calendar +const calendars = new Set(Intl.supportedValuesOf("calendar")); +calendars.delete("iso8601"); +calendars.delete(localeCalendar); +const differentCalendar = calendars.values().next().value; + +const differentCalendarInstance = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: differentCalendar }); +assert.throws(RangeError, () => differentCalendarInstance.toLocaleString(), "calendar mismatch"); + +const isoInstance = Temporal.PlainMonthDay.from({ monthCode: "M01", day: 1, calendar: "iso8601" }); +assert.throws(RangeError, () => isoInstance.toLocaleString(), "calendar mismatch even when instance has the ISO calendar") diff --git a/test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/calendar-mismatch.js b/test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/calendar-mismatch.js new file mode 100644 index 0000000000..6785efd362 --- /dev/null +++ b/test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/calendar-mismatch.js @@ -0,0 +1,27 @@ +// Copyright (C) 2023 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: Calendar must match the locale calendar +features: [Temporal, Intl-enumeration] +---*/ + +const localeCalendar = new Intl.DateTimeFormat().resolvedOptions().calendar; +assert.notSameValue(localeCalendar, "iso8601", "no locale has the ISO calendar"); + +const sameCalendarInstance = new Temporal.PlainDate(2000, 1, 1, localeCalendar).toPlainYearMonth(); +const result = sameCalendarInstance.toLocaleString(); +assert.sameValue(typeof result, "string", "toLocaleString() succeeds when instance has the same calendar as locale"); + +// Pick a different calendar that is not ISO and not the locale's calendar +const calendars = new Set(Intl.supportedValuesOf("calendar")); +calendars.delete("iso8601"); +calendars.delete(localeCalendar); +const differentCalendar = calendars.values().next().value; + +const differentCalendarInstance = new Temporal.PlainDate(2000, 1, 1, differentCalendar).toPlainYearMonth(); +assert.throws(RangeError, () => differentCalendarInstance.toLocaleString(), "calendar mismatch"); + +const isoInstance = new Temporal.PlainDate(2000, 1, 1, "iso8601").toPlainYearMonth(); +assert.throws(RangeError, () => isoInstance.toLocaleString(), "calendar mismatch even when instance has the ISO calendar") diff --git a/test/staging/Intl402/Temporal/old/date-toLocaleString.js b/test/staging/Intl402/Temporal/old/date-toLocaleString.js index 282b22850e..8b90b223cc 100644 --- a/test/staging/Intl402/Temporal/old/date-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/date-toLocaleString.js @@ -31,28 +31,3 @@ assert.sameValue(date.toLocaleString("en-US", { timeZoneName: "long" }), "11/18/ assert.sameValue(date.toLocaleString("en-US", { hour: "numeric" }), "11/18/1976"); assert.sameValue(date.toLocaleString("en-US", { minute: "numeric" }), "11/18/1976"); assert.sameValue(date.toLocaleString("en-US", { second: "numeric" }), "11/18/1976"); - -// works when the object's calendar is the same as the locale's calendar -var d = Temporal.PlainDate.from({ - era: "showa", - eraYear: 51, - month: 11, - day: 18, - calendar: "japanese" -}); -var result = d.toLocaleString("en-US-u-ca-japanese"); -assert(result === "11/18/51" || result === "11/18/51 S"); - -// adopts the locale's calendar when the object's calendar is ISO -var d = Temporal.PlainDate.from("1976-11-18"); -var result = d.toLocaleString("en-US-u-ca-japanese"); -assert(result === "11/18/51" || result === "11/18/51 S"); - -// throws when the calendars are different and not ISO -var d = Temporal.PlainDate.from({ - year: 1976, - month: 11, - day: 18, - calendar: "gregory" -}); -assert.throws(RangeError, () => d.toLocaleString("en-US-u-ca-japanese")); diff --git a/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js b/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js index 65a7bcdbef..c5889e0ecb 100644 --- a/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js @@ -49,34 +49,3 @@ assert.sameValue( `${dstStart.toLocaleString("en-US", { timeZone: "America/Los_Angeles" })}`, `3/8/2020, 3:30:00${usDayPeriodSpace}AM` ); - -// works when the object's calendar is the same as the locale's calendar -var dt = Temporal.PlainDateTime.from({ - era: "showa", - eraYear: 51, - month: 11, - day: 18, - hour: 15, - minute: 23, - second: 30, - calendar: "japanese" -}); -var result = dt.toLocaleString("en-US-u-ca-japanese"); -assert(result === `11/18/51, 3:23:30${usDayPeriodSpace}PM` || result === `11/18/51 S, 3:23:30${usDayPeriodSpace}PM`); - -// adopts the locale's calendar when the object's calendar is ISO -var dt = Temporal.PlainDateTime.from("1976-11-18T15:23:30"); -var result = dt.toLocaleString("en-US-u-ca-japanese"); -assert(result === `11/18/51, 3:23:30${usDayPeriodSpace}PM` || result === `11/18/51 S, 3:23:30${usDayPeriodSpace}PM`); - -// throws when the calendars are different and not ISO -var dt = Temporal.PlainDateTime.from({ - year: 1976, - month: 11, - day: 18, - hour: 15, - minute: 23, - second: 30, - calendar: "gregory" -}); -assert.throws(RangeError, () => dt.toLocaleString("en-US-u-ca-japanese")); diff --git a/test/staging/Intl402/Temporal/old/monthday-toLocaleString.js b/test/staging/Intl402/Temporal/old/monthday-toLocaleString.js index d064ef2736..8b21023074 100644 --- a/test/staging/Intl402/Temporal/old/monthday-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/monthday-toLocaleString.js @@ -26,18 +26,3 @@ assert.sameValue(monthday.toLocaleString("en-US", { hour: "numeric" }), "11/18") assert.sameValue(monthday.toLocaleString("en-US", { minute: "numeric" }), "11/18"); assert.sameValue(monthday.toLocaleString("en-US", { second: "numeric" }), "11/18"); assert.sameValue(monthday.toLocaleString("en-US", { weekday: "long" }), "11/18"); - -// works when the object's calendar is the same as the locale's calendar -var md = Temporal.PlainMonthDay.from({ - monthCode: "M11", - day: 18, - calendar: "japanese" -}); -assert.sameValue(`${ md.toLocaleString("en-US-u-ca-japanese") }`, "11/18"); - -// throws when the calendar is not equal to the locale calendar -var mdISO = Temporal.PlainMonthDay.from({ - month: 11, - day: 18 -}); -assert.throws(RangeError, () => mdISO.toLocaleString("en-US-u-ca-japanese")); diff --git a/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js b/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js index 8e8a1d3146..fc80d3bcac 100644 --- a/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js @@ -37,20 +37,3 @@ assert.sameValue(yearmonth.toLocaleString("en-US", { hour: "numeric" }), "11/197 assert.sameValue(yearmonth.toLocaleString("en-US", { minute: "numeric" }), "11/1976"); assert.sameValue(yearmonth.toLocaleString("en-US", { second: "numeric" }), "11/1976"); assert.sameValue(yearmonth.toLocaleString("en-US", { weekday: "long" }), "11/1976"); - -// works when the object's calendar is the same as the locale's calendar -var ym = Temporal.PlainYearMonth.from({ - era: "showa", - eraYear: 51, - month: 11, - calendar: "japanese" -}); -var result = ym.toLocaleString("en-US-u-ca-japanese"); -assert(result === "11/51" || result === "11/51 S"); - -// throws when the calendar is not equal to the locale calendar -var ymISO = Temporal.PlainYearMonth.from({ - year: 1976, - month: 11 -}); -assert.throws(RangeError, () => ymISO.toLocaleString("en-US-u-ca-japanese"));