mirror of
https://github.com/tc39/test262.git
synced 2025-07-27 07:54:41 +02:00
Temporal: Port toLocaleString calendar mismatch tests from staging
I wrote a similar test for Temporal.ZonedDateTime.p.toLocaleString, so while this was fresh I decided to do the same for the other toLocaleString calendar mismatch tests that were in staging.
This commit is contained in:
parent
cd714a9aad
commit
801a5bb8f5
27
test/intl402/Temporal/PlainDate/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
27
test/intl402/Temporal/PlainDate/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
@ -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");
|
27
test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
27
test/intl402/Temporal/PlainDateTime/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
@ -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");
|
27
test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
27
test/intl402/Temporal/PlainMonthDay/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
@ -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")
|
27
test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
27
test/intl402/Temporal/PlainYearMonth/prototype/toLocaleString/calendar-mismatch.js
vendored
Normal file
@ -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")
|
@ -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", { hour: "numeric" }), "11/18/1976");
|
||||||
assert.sameValue(date.toLocaleString("en-US", { minute: "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");
|
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"));
|
|
||||||
|
@ -49,34 +49,3 @@ assert.sameValue(
|
|||||||
`${dstStart.toLocaleString("en-US", { timeZone: "America/Los_Angeles" })}`,
|
`${dstStart.toLocaleString("en-US", { timeZone: "America/Los_Angeles" })}`,
|
||||||
`3/8/2020, 3:30:00${usDayPeriodSpace}AM`
|
`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"));
|
|
||||||
|
@ -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", { minute: "numeric" }), "11/18");
|
||||||
assert.sameValue(monthday.toLocaleString("en-US", { second: "numeric" }), "11/18");
|
assert.sameValue(monthday.toLocaleString("en-US", { second: "numeric" }), "11/18");
|
||||||
assert.sameValue(monthday.toLocaleString("en-US", { weekday: "long" }), "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"));
|
|
||||||
|
@ -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", { minute: "numeric" }), "11/1976");
|
||||||
assert.sameValue(yearmonth.toLocaleString("en-US", { second: "numeric" }), "11/1976");
|
assert.sameValue(yearmonth.toLocaleString("en-US", { second: "numeric" }), "11/1976");
|
||||||
assert.sameValue(yearmonth.toLocaleString("en-US", { weekday: "long" }), "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"));
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user