diff --git a/test/staging/Intl402/Temporal/old/date-time-format.js b/test/staging/Intl402/Temporal/old/date-time-format.js index ba51c1cd2e..f2410131e3 100644 --- a/test/staging/Intl402/Temporal/old/date-time-format.js +++ b/test/staging/Intl402/Temporal/old/date-time-format.js @@ -8,8 +8,36 @@ includes: [deepEqual.js] features: [Temporal] ---*/ -// should return an Array +// Tolerate implementation variance by expecting consistency without being prescriptive. +// TODO: can we change tests to be less reliant on CLDR formats while still testing that +// Temporal and Intl are behaving as expected? +const usDayPeriodSpace = + new Intl.DateTimeFormat("en-US", { timeStyle: "short" }) + .formatToParts(0) + .find((part, i, parts) => part.type === "literal" && parts[i + 1].type === "dayPeriod")?.value || ""; +const usDateRangeSeparator = new Intl.DateTimeFormat("en-US", { dateStyle: "short" }) + .formatRangeToParts(1 * 86400 * 1000, 366 * 86400 * 1000) + .find((part) => part.type === "literal" && part.source === "shared").value; +const deDateRangeSeparator = new Intl.DateTimeFormat("de-AT", { dateStyle: "short" }) + .formatRangeToParts(1 * 86400 * 1000, 366 * 86400 * 1000) + .find((part) => part.type === "literal" && part.source === "shared").value; +// Workarounds for https:// unicode-org.atlassian.net/browse/CLDR-16243 +const deMonthDayRangeSeparator = new Intl.DateTimeFormat("de-AT", { month: "numeric", day: "numeric" }) + .formatRangeToParts(1 * 86400 * 1000, 90 * 86400 * 1000) + .find((part) => part.type === "literal" && part.source === "shared").value; +const deMonthYearSeparator = new Intl.DateTimeFormat("de-AT", { year: "numeric", month: "numeric" }) + .formatToParts(0) + .find((part) => part.type === "literal").value; +const deMonthInYearMonthHasLeadingZero = new Intl.DateTimeFormat("de-AT", { + year: "numeric", + month: "numeric" +}) + .formatToParts(new Date(2000, 3, 1)) + .find((part) => part.type === "month") + .value.startsWith("0"); + +// should return an Array assert(Array.isArray(Intl.DateTimeFormat.supportedLocalesOf())); var onlyOnce = (value) => { var obj = { @@ -52,19 +80,19 @@ var start = new Date("1922-12-30"); var end = new Date("1991-12-26"); // should work for Instant -assert.sameValue(us.format(Temporal.Instant.from(t1)), "11/18/1976, 9:23:30 AM"); +assert.sameValue(us.format(Temporal.Instant.from(t1)), `11/18/1976, 9:23:30${usDayPeriodSpace}AM`); assert.sameValue(at.format(Temporal.Instant.from(t1)), "18.11.1976, 15:23:30"); // should work for ZonedDateTime -assert.sameValue(us2.format(Temporal.ZonedDateTime.from(t1)), "11/18/1976, 2:23:30 PM UTC"); +assert.sameValue(us2.format(Temporal.ZonedDateTime.from(t1)), `11/18/1976, 2:23:30${usDayPeriodSpace}PM UTC`); assert.sameValue(at2.format(Temporal.ZonedDateTime.from(t1)), "18.11.1976, 14:23:30 UTC"); // should work for DateTime -assert.sameValue(us.format(Temporal.PlainDateTime.from(t1)), "11/18/1976, 2:23:30 PM"); +assert.sameValue(us.format(Temporal.PlainDateTime.from(t1)), `11/18/1976, 2:23:30${usDayPeriodSpace}PM`); assert.sameValue(at.format(Temporal.PlainDateTime.from(t1)), "18.11.1976, 14:23:30"); // should work for Time -assert.sameValue(us.format(Temporal.PlainTime.from(t1)), "2:23:30 PM"); +assert.sameValue(us.format(Temporal.PlainTime.from(t1)), `2:23:30${usDayPeriodSpace}PM`); assert.sameValue(at.format(Temporal.PlainTime.from(t1)), "14:23:30"); // should work for Date @@ -74,7 +102,7 @@ assert.sameValue(at.format(Temporal.PlainDate.from(t1)), "18.11.1976"); // should work for YearMonth var t = Temporal.PlainDate.from(t1); assert.sameValue(us.format(t.withCalendar(usCalendar).toPlainYearMonth()), "11/1976"); -assert.sameValue(at.format(t.withCalendar(atCalendar).toPlainYearMonth()), "11.1976"); +assert.sameValue(at.format(t.withCalendar(atCalendar).toPlainYearMonth()), `11${deMonthYearSeparator}1976`); // should work for MonthDay var t = Temporal.PlainDate.from(t1); @@ -133,7 +161,7 @@ assert.deepEqual(us.formatToParts(Temporal.Instant.from(t2)), [ }, { type: "literal", - value: " " + value: usDayPeriodSpace }, { type: "dayPeriod", @@ -234,7 +262,7 @@ assert.deepEqual(us2.formatToParts(Temporal.ZonedDateTime.from(t2)), [ }, { type: "literal", - value: " " + value: usDayPeriodSpace }, { type: "dayPeriod", @@ -351,7 +379,7 @@ assert.deepEqual(us.formatToParts(Temporal.PlainDateTime.from(t2)), [ }, { type: "literal", - value: " " + value: usDayPeriodSpace }, { type: "dayPeriod", @@ -428,7 +456,7 @@ assert.deepEqual(us.formatToParts(Temporal.PlainTime.from(t2)), [ }, { type: "literal", - value: " " + value: usDayPeriodSpace }, { type: "dayPeriod", @@ -521,11 +549,11 @@ assert.deepEqual(us.formatToParts(t.withCalendar(usCalendar).toPlainYearMonth()) assert.deepEqual(at.formatToParts(t.withCalendar(atCalendar).toPlainYearMonth()), [ { type: "month", - value: "2" + value: deMonthInYearMonthHasLeadingZero ? "02" : "2" }, { type: "literal", - value: "." + value: deMonthYearSeparator }, { type: "year", @@ -615,44 +643,50 @@ assert.deepEqual(at.formatToParts(end), [ // should work for Instant assert.sameValue( us.formatRange(Temporal.Instant.from(t1), Temporal.Instant.from(t2)), - "11/18/1976, 9:23:30 AM \u2013 2/20/2020, 3:44:56 PM" + `11/18/1976, 9:23:30${usDayPeriodSpace}AM${usDateRangeSeparator}2/20/2020, 3:44:56${usDayPeriodSpace}PM` ); assert.sameValue( at.formatRange(Temporal.Instant.from(t1), Temporal.Instant.from(t2)), - "18.11.1976, 15:23:30 \u2013 20.2.2020, 21:44:56" + `18.11.1976, 15:23:30${deDateRangeSeparator}20.2.2020, 21:44:56` ); // should work for ZonedDateTime var zdt1 = Temporal.ZonedDateTime.from(t1); var zdt2 = Temporal.ZonedDateTime.from(t2).withTimeZone(zdt1.timeZone); -assert.sameValue(us2.formatRange(zdt1, zdt2), "11/18/1976, 2:23:30 PM UTC \u2013 2/20/2020, 8:44:56 PM UTC"); -assert.sameValue(at2.formatRange(zdt1, zdt2), "18.11.1976, 14:23:30 UTC \u2013 20.2.2020, 20:44:56 UTC"); +assert.sameValue( + us2.formatRange(zdt1, zdt2), + `11/18/1976, 2:23:30${usDayPeriodSpace}PM UTC${usDateRangeSeparator}2/20/2020, 8:44:56${usDayPeriodSpace}PM UTC` +); +assert.sameValue(at2.formatRange(zdt1, zdt2), `18.11.1976, 14:23:30 UTC${deDateRangeSeparator}20.2.2020, 20:44:56 UTC`); // should work for DateTime assert.sameValue( us.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)), - "11/18/1976, 2:23:30 PM \u2013 2/20/2020, 3:44:56 PM" + `11/18/1976, 2:23:30${usDayPeriodSpace}PM${usDateRangeSeparator}2/20/2020, 3:44:56${usDayPeriodSpace}PM` ); assert.sameValue( at.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)), - "18.11.1976, 14:23:30 \u2013 20.2.2020, 15:44:56" + `18.11.1976, 14:23:30${deDateRangeSeparator}20.2.2020, 15:44:56` ); // should work for Time assert.sameValue( us.formatRange(Temporal.PlainTime.from(t1), Temporal.PlainTime.from(t2)), - "2:23:30 PM \u2013 3:44:56 PM" + `2:23:30${usDayPeriodSpace}PM${usDateRangeSeparator}3:44:56${usDayPeriodSpace}PM` +); +assert.sameValue( + at.formatRange(Temporal.PlainTime.from(t1), Temporal.PlainTime.from(t2)), + `14:23:30${deDateRangeSeparator}15:44:56` ); -assert.sameValue(at.formatRange(Temporal.PlainTime.from(t1), Temporal.PlainTime.from(t2)), "14:23:30 \u2013 15:44:56"); // should work for Date assert.sameValue( us.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2)), - "11/18/1976 \u2013 2/20/2020" + `11/18/1976${usDateRangeSeparator}2/20/2020` ); assert.sameValue( at.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2)), - "18.11.1976 \u2013 20.02.2020" + `18.11.1976${deDateRangeSeparator}20.02.2020` ); // should work for YearMonth @@ -660,11 +694,11 @@ var date1 = Temporal.PlainDate.from(t1); var date2 = Temporal.PlainDate.from(t2); assert.sameValue( us.formatRange(date1.withCalendar(usCalendar).toPlainYearMonth(), date2.withCalendar(usCalendar).toPlainYearMonth()), - "11/1976 \u2013 2/2020" + `11/1976${usDateRangeSeparator}2/2020` ); assert.sameValue( at.formatRange(date1.withCalendar(atCalendar).toPlainYearMonth(), date2.withCalendar(atCalendar).toPlainYearMonth()), - "11.1976 \u2013 02.2020" + `11${deMonthYearSeparator}1976${deDateRangeSeparator}02${deMonthYearSeparator}2020` ); // should work for MonthDay @@ -672,18 +706,17 @@ var date1 = Temporal.PlainDate.from(t1); var date2 = Temporal.PlainDate.from(t2); assert.sameValue( us.formatRange(date2.withCalendar(usCalendar).toPlainMonthDay(), date1.withCalendar(usCalendar).toPlainMonthDay()), - "2/20 \u2013 11/18" + `2/20${usDateRangeSeparator}11/18` ); assert.sameValue( at.formatRange(date2.withCalendar(atCalendar).toPlainMonthDay(), date1.withCalendar(atCalendar).toPlainMonthDay()), - "20.02. \u2013 18.11." + `20.02${deMonthDayRangeSeparator}18.11.` ); // should not break legacy Date -assert.sameValue(us.formatRange(start, end), "12/29/1922 \u2013 12/25/1991"); -assert.sameValue(at.formatRange(start, end), "30.12.1922 \u2013 26.12.1991"); +assert.sameValue(us.formatRange(start, end), `12/29/1922${usDateRangeSeparator}12/25/1991`); +assert.sameValue(at.formatRange(start, end), `30.12.1922${deDateRangeSeparator}26.12.1991`); -// should throw a TypeError when called with dissimilar types", () => assert.throws(TypeError, () => us.formatRange(Temporal.Instant.from(t1), Temporal.PlainDateTime.from(t2)))); // should throw a RangeError when called with different calendars assert.throws(RangeError, () => us.formatRange(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2).withCalendar("japanese")) @@ -755,7 +788,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Insta }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "startRange" }, { @@ -765,7 +798,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Insta }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -825,7 +858,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Insta }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "endRange" }, { @@ -892,7 +925,7 @@ assert.deepEqual(at.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Insta }, { type: "literal", - value: " \u2013 ", + value: deDateRangeSeparator, source: "shared" }, { @@ -1013,7 +1046,7 @@ assert.deepEqual(us2.formatRangeToParts(zdt1, zdt2), [ }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "startRange" }, { @@ -1033,7 +1066,7 @@ assert.deepEqual(us2.formatRangeToParts(zdt1, zdt2), [ }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -1093,7 +1126,7 @@ assert.deepEqual(us2.formatRangeToParts(zdt1, zdt2), [ }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "endRange" }, { @@ -1180,7 +1213,7 @@ assert.deepEqual(at2.formatRangeToParts(zdt1, zdt2), [ }, { type: "literal", - value: " \u2013 ", + value: deDateRangeSeparator, source: "shared" }, { @@ -1308,7 +1341,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "startRange" }, { @@ -1318,7 +1351,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -1378,7 +1411,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "endRange" }, { @@ -1445,7 +1478,7 @@ assert.deepEqual(at.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal }, { type: "literal", - value: " \u2013 ", + value: deDateRangeSeparator, source: "shared" }, { @@ -1533,7 +1566,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.PlainTime.from(t1), Temporal.Pla }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "startRange" }, { @@ -1543,7 +1576,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.PlainTime.from(t1), Temporal.Pla }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -1573,7 +1606,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.PlainTime.from(t1), Temporal.Pla }, { type: "literal", - value: " ", + value: usDayPeriodSpace, source: "endRange" }, { @@ -1610,7 +1643,7 @@ assert.deepEqual(at.formatRangeToParts(Temporal.PlainTime.from(t1), Temporal.Pla }, { type: "literal", - value: " \u2013 ", + value: deDateRangeSeparator, source: "shared" }, { @@ -1668,7 +1701,7 @@ assert.deepEqual(us.formatRangeToParts(Temporal.PlainDate.from(t1), Temporal.Pla }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -1725,7 +1758,7 @@ assert.deepEqual(at.formatRangeToParts(Temporal.PlainDate.from(t1), Temporal.Pla }, { type: "literal", - value: " \u2013 ", + value: deDateRangeSeparator, source: "shared" }, { @@ -1780,7 +1813,7 @@ assert.deepEqual( }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -1813,7 +1846,7 @@ assert.deepEqual( }, { type: "literal", - value: ".", + value: deMonthYearSeparator, source: "startRange" }, { @@ -1823,7 +1856,7 @@ assert.deepEqual( }, { type: "literal", - value: " \u2013 ", + value: deDateRangeSeparator, source: "shared" }, { @@ -1833,7 +1866,7 @@ assert.deepEqual( }, { type: "literal", - value: ".", + value: deMonthYearSeparator, source: "endRange" }, { @@ -1869,7 +1902,7 @@ assert.deepEqual( }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -1912,7 +1945,7 @@ assert.deepEqual( }, { type: "literal", - value: ". \u2013 ", + value: deMonthDayRangeSeparator, source: "shared" }, { @@ -1966,7 +1999,7 @@ assert.deepEqual(us.formatRangeToParts(start, end), [ }, { type: "literal", - value: " \u2013 ", + value: usDateRangeSeparator, source: "shared" }, { @@ -2023,7 +2056,7 @@ assert.deepEqual(at.formatRangeToParts(start, end), [ }, { type: "literal", - value: " \u2013 ", + value: deDateRangeSeparator, source: "shared" }, { diff --git a/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js b/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js index ee88de87bc..65a7bcdbef 100644 --- a/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/datetime-toLocaleString.js @@ -7,6 +7,14 @@ description: datetime.toLocaleString() features: [Temporal] ---*/ +// Tolerate implementation variance by expecting consistency without being prescriptive. +// TODO: can we change tests to be less reliant on CLDR formats while still testing that +// Temporal and Intl are behaving as expected? +const usDayPeriodSpace = + new Intl.DateTimeFormat("en-US", { timeStyle: "short" }) + .formatToParts(0) + .find((part, i, parts) => part.type === "literal" && parts[i + 1].type === "dayPeriod")?.value || ""; + function maybeGetWeekdayOnlyFormat() { const fmt = new Intl.DateTimeFormat("en-US", { weekday: "long", timeZone: "Europe/Vienna" }); if ( @@ -21,17 +29,26 @@ function maybeGetWeekdayOnlyFormat() { } var datetime = Temporal.PlainDateTime.from("1976-11-18T15:23:30"); -assert.sameValue(`${datetime.toLocaleString("en-US", { timeZone: "America/New_York" })}`, "11/18/1976, 3:23:30 PM"); +assert.sameValue( + `${datetime.toLocaleString("en-US", { timeZone: "America/New_York" })}`, + `11/18/1976, 3:23:30${usDayPeriodSpace}PM` +); assert.sameValue(`${datetime.toLocaleString("de-AT", { timeZone: "Europe/Vienna" })}`, "18.11.1976, 15:23:30"); var fmt = maybeGetWeekdayOnlyFormat(); if (fmt) assert.sameValue(fmt.format(datetime), "Thursday"); // should ignore units not in the data type -assert.sameValue(datetime.toLocaleString("en-US", { timeZoneName: "long" }), "11/18/1976, 3:23:30 PM"); +assert.sameValue( + datetime.toLocaleString("en-US", { timeZoneName: "long" }), + `11/18/1976, 3:23:30${usDayPeriodSpace}PM` +); // should use compatible disambiguation option var dstStart = new Temporal.PlainDateTime(2020, 3, 8, 2, 30); -assert.sameValue(`${dstStart.toLocaleString("en-US", { timeZone: "America/Los_Angeles" })}`, "3/8/2020, 3:30:00 AM"); +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({ @@ -45,12 +62,12 @@ var dt = Temporal.PlainDateTime.from({ calendar: "japanese" }); var result = dt.toLocaleString("en-US-u-ca-japanese"); -assert(result === "11/18/51, 3:23:30 PM" || result === "11/18/51 S, 3:23:30 PM"); +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 PM" || result === "11/18/51 S, 3:23:30 PM"); +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({ diff --git a/test/staging/Intl402/Temporal/old/instant-toLocaleString.js b/test/staging/Intl402/Temporal/old/instant-toLocaleString.js index d7b92c7998..5c18da4dcd 100644 --- a/test/staging/Intl402/Temporal/old/instant-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/instant-toLocaleString.js @@ -7,6 +7,14 @@ description: Instant.toLocaleString() features: [Temporal] ---*/ +// Tolerate implementation variance by expecting consistency without being prescriptive. +// TODO: can we change tests to be less reliant on CLDR formats while still testing that +// Temporal and Intl are behaving as expected? +const usDayPeriodSpace = + new Intl.DateTimeFormat("en-US", { timeStyle: "short" }) + .formatToParts(0) + .find((part, i, parts) => part.type === "literal" && parts[i + 1].type === "dayPeriod")?.value || ""; + function maybeGetWeekdayOnlyFormat() { const fmt = new Intl.DateTimeFormat("en-US", { weekday: "long", timeZone: "Europe/Vienna" }); if ( @@ -21,7 +29,10 @@ function maybeGetWeekdayOnlyFormat() { } var instant = Temporal.Instant.from("1976-11-18T14:23:30Z"); -assert.sameValue(`${instant.toLocaleString("en-US", { timeZone: "America/New_York" })}`, "11/18/1976, 9:23:30 AM"); +assert.sameValue( + `${instant.toLocaleString("en-US", { timeZone: "America/New_York" })}`, + `11/18/1976, 9:23:30${usDayPeriodSpace}AM` +); assert.sameValue(`${instant.toLocaleString("de-AT", { timeZone: "Europe/Vienna" })}`, "18.11.1976, 15:23:30"); var fmt = maybeGetWeekdayOnlyFormat(); if (fmt) assert.sameValue(fmt.format(instant), "Thursday"); diff --git a/test/staging/Intl402/Temporal/old/time-toLocaleString.js b/test/staging/Intl402/Temporal/old/time-toLocaleString.js index 331dccc74f..1ab7b0776b 100644 --- a/test/staging/Intl402/Temporal/old/time-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/time-toLocaleString.js @@ -7,13 +7,21 @@ description: time.toLocaleString() features: [Temporal] ---*/ +// Tolerate implementation variance by expecting consistency without being prescriptive. +// TODO: can we change tests to be less reliant on CLDR formats while still testing that +// Temporal and Intl are behaving as expected? +const usDayPeriodSpace = + new Intl.DateTimeFormat("en-US", { timeStyle: "short" }) + .formatToParts(0) + .find((part, i, parts) => part.type === "literal" && parts[i + 1].type === "dayPeriod")?.value || ""; + var time = Temporal.PlainTime.from("1976-11-18T15:23:30"); -assert.sameValue(`${time.toLocaleString("en-US", { timeZone: "America/New_York" })}`, "3:23:30 PM"); +assert.sameValue(`${time.toLocaleString("en-US", { timeZone: "America/New_York" })}`, `3:23:30${usDayPeriodSpace}PM`); assert.sameValue(`${time.toLocaleString("de-AT", { timeZone: "Europe/Vienna" })}`, "15:23:30"); // should ignore units not in the data type -assert.sameValue(time.toLocaleString("en-US", { timeZoneName: "long" }), "3:23:30 PM"); -assert.sameValue(time.toLocaleString("en-US", { year: "numeric" }), "3:23:30 PM"); -assert.sameValue(time.toLocaleString("en-US", { month: "numeric" }), "3:23:30 PM"); -assert.sameValue(time.toLocaleString("en-US", { day: "numeric" }), "3:23:30 PM"); -assert.sameValue(time.toLocaleString("en-US", { weekday: "long" }), "3:23:30 PM"); +assert.sameValue(time.toLocaleString("en-US", { timeZoneName: "long" }), `3:23:30${usDayPeriodSpace}PM`); +assert.sameValue(time.toLocaleString("en-US", { year: "numeric" }), `3:23:30${usDayPeriodSpace}PM`); +assert.sameValue(time.toLocaleString("en-US", { month: "numeric" }), `3:23:30${usDayPeriodSpace}PM`); +assert.sameValue(time.toLocaleString("en-US", { day: "numeric" }), `3:23:30${usDayPeriodSpace}PM`); +assert.sameValue(time.toLocaleString("en-US", { weekday: "long" }), `3:23:30${usDayPeriodSpace}PM`); diff --git a/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js b/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js index f9192ca4b2..8e8a1d3146 100644 --- a/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/yearmonth-toLocaleString.js @@ -7,6 +7,17 @@ description: yearmonth.toLocaleString() features: [Temporal] ---*/ +// Tolerate implementation variance by expecting consistency without being prescriptive. +// TODO: can we change tests to be less reliant on CLDR formats while still testing that +// Temporal and Intl are behaving as expected? +// Workarounds for https://unicode-org.atlassian.net/browse/CLDR-16243 +const deMonthDayRangeSeparator = new Intl.DateTimeFormat("de-AT", { month: "numeric", day: "numeric" }) + .formatRangeToParts(1 * 86400 * 1000, 90 * 86400 * 1000) + .find((part) => part.type === "literal" && part.source === "shared").value; +const deMonthYearSeparator = new Intl.DateTimeFormat("de-AT", { year: "numeric", month: "numeric" }) + .formatToParts(0) + .find((part) => part.type === "literal").value; + var calendar = new Intl.DateTimeFormat("en-US").resolvedOptions().calendar; var yearmonth = Temporal.PlainYearMonth.from({ year: 1976, @@ -15,11 +26,8 @@ var yearmonth = Temporal.PlainYearMonth.from({ }); assert.sameValue(`${yearmonth.toLocaleString("en-US", { timeZone: "America/New_York" })}`, "11/1976"); assert.sameValue( - `${yearmonth.toLocaleString("de-AT", { - timeZone: "Europe/Vienna", - calendar - })}`, - "11.1976" + `${yearmonth.toLocaleString("de-AT", { timeZone: "Europe/Vienna", calendar })}`, + `11${deMonthYearSeparator}1976` ); // should ignore units not in the data type diff --git a/test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js b/test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js index 39d6fea936..b96dfeebc9 100644 --- a/test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js +++ b/test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js @@ -7,6 +7,14 @@ description: zoneddatetime.toLocaleString() features: [Temporal] ---*/ +// Tolerate implementation variance by expecting consistency without being prescriptive. +// TODO: can we change tests to be less reliant on CLDR formats while still testing that +// Temporal and Intl are behaving as expected? +const usDayPeriodSpace = + new Intl.DateTimeFormat("en-US", { timeStyle: "short" }) + .formatToParts(0) + .find((part, i, parts) => part.type === "literal" && parts[i + 1].type === "dayPeriod")?.value || ""; + function maybeGetWeekdayOnlyFormat() { const fmt = new Intl.DateTimeFormat("en-US", { weekday: "long", timeZone: "Europe/Vienna" }); if ( @@ -21,7 +29,7 @@ function maybeGetWeekdayOnlyFormat() { } var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30+01:00[Europe/Vienna]"); -assert.sameValue(zdt.toLocaleString("en-US"), "11/18/1976, 3:23:30 PM GMT+1"); +assert.sameValue(zdt.toLocaleString("en-US"), `11/18/1976, 3:23:30${usDayPeriodSpace}PM GMT+1`); assert.sameValue(zdt.toLocaleString("de-AT"), "18.11.1976, 15:23:30 MEZ"); const fmt = maybeGetWeekdayOnlyFormat(); @@ -30,11 +38,14 @@ if (fmt) assert.sameValue(fmt.format(zdt), "Thursday"); // can override the style of the time zone name assert.sameValue( zdt.toLocaleString("en-US", { timeZoneName: "long" }), - "11/18/1976, 3:23:30 PM Central European Standard Time" + `11/18/1976, 3:23:30${usDayPeriodSpace}PM Central European Standard Time` ); // works if the time zone given in options agrees with the object's time zone -assert.sameValue(zdt.toLocaleString("en-US", { timeZone: "Europe/Vienna" }), "11/18/1976, 3:23:30 PM GMT+1"); +assert.sameValue( + zdt.toLocaleString("en-US", { timeZone: "Europe/Vienna" }), + `11/18/1976, 3:23:30${usDayPeriodSpace}PM GMT+1` +); // throws if the time zone given in options disagrees with the object's time zone assert.throws(RangeError, () => zdt.toLocaleString("en-US", { timeZone: "America/New_York" })); @@ -42,12 +53,16 @@ assert.throws(RangeError, () => zdt.toLocaleString("en-US", { timeZone: "America // works when the object's calendar is the same as the locale's calendar var zdt = new Temporal.ZonedDateTime(0n, "UTC", "japanese"); var result = zdt.toLocaleString("en-US-u-ca-japanese"); -assert(result === "1/1/45, 12:00:00 AM UTC" || result === "1/1/45 S, 12:00:00 AM UTC"); +assert( + result === `1/1/45, 12:00:00${usDayPeriodSpace}AM UTC` || result === `1/1/45 S, 12:00:00${usDayPeriodSpace}AM UTC` +); // adopts the locale's calendar when the object's calendar is ISO var zdt = Temporal.ZonedDateTime.from("1976-11-18T15:23:30+00:00[UTC]"); var result = zdt.toLocaleString("en-US-u-ca-japanese"); -assert(result === "11/18/51, 3:23:30 PM UTC" || result === "11/18/51 S, 3:23:30 PM UTC"); +assert( + result === `11/18/51, 3:23:30${usDayPeriodSpace}PM UTC` || result === `11/18/51 S, 3:23:30${usDayPeriodSpace}PM UTC` +); // throws when the calendars are different and not ISO var zdt = new Temporal.ZonedDateTime(0n, "UTC", "gregory");