From cd714a9aada12cfd8152b7389f025aeb13df5495 Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Mon, 10 Apr 2023 12:21:16 -0700 Subject: [PATCH] Temporal: Rewrite Temporal.ZonedDateTime.p.toLocaleString tests In https://github.com/tc39/proposal-temporal/pull/2522 which reached consensus at the March 2023 TC39 meeting, the functionality of Temporal.ZonedDateTime.p.toLocaleString was changed substantially, to not directly pass the ZonedDateTime to any Intl.DateTimeFormat methods. This adds rewrites of all existing tests for toLocaleString, as well as a few tests to verify that Intl.DateTimeFormat methods no longer support Temporal.ZonedDateTime arguments. As we are rewriting the tests anyway, this also ports all of the Temporal.ZonedDateTime.p.toLocaleString tests that were in staging, to the correct format for the main tree. --- .../temporal-zoneddatetime-not-supported.js | 17 + .../temporal-zoneddatetime-not-supported.js | 18 + .../temporal-zoneddatetime-not-supported.js | 18 + .../temporal-zoneddatetime-not-supported.js | 17 + .../toLocaleString/calendar-mismatch.js | 27 ++ .../custom-time-zone-name-not-supported.js | 17 + .../toLocaleString/locales-undefined.js | 13 +- .../offset-time-zone-not-supported.js | 11 + .../toLocaleString/options-timeZone.js | 15 + ...timeZoneName-affects-instance-time-zone.js | 16 + .../toLocaleString/options-undefined.js | 13 +- .../toLocaleString/time-zone-canonicalized.js | 24 + .../Intl402/Temporal/old/date-time-format.js | 435 ------------------ .../old/zoneddatetime-toLocaleString.js | 69 --- 14 files changed, 202 insertions(+), 508 deletions(-) create mode 100644 test/intl402/DateTimeFormat/prototype/format/temporal-zoneddatetime-not-supported.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRange/temporal-zoneddatetime-not-supported.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-zoneddatetime-not-supported.js create mode 100644 test/intl402/DateTimeFormat/prototype/formatToParts/temporal-zoneddatetime-not-supported.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/calendar-mismatch.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/custom-time-zone-name-not-supported.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/offset-time-zone-not-supported.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZone.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZoneName-affects-instance-time-zone.js create mode 100644 test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js delete mode 100644 test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js diff --git a/test/intl402/DateTimeFormat/prototype/format/temporal-zoneddatetime-not-supported.js b/test/intl402/DateTimeFormat/prototype/format/temporal-zoneddatetime-not-supported.js new file mode 100644 index 0000000000..9493dcffc4 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/format/temporal-zoneddatetime-not-supported.js @@ -0,0 +1,17 @@ +// Copyright (C) 2023 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: Temporal.ZonedDateTime is not supported directly in format() +features: [Temporal] +---*/ + +const formatter = new Intl.DateTimeFormat(); + +// Check that TypeError would not be thrown for a different reason +const {timeZone, ...options} = formatter.resolvedOptions(); +const datetime = new Temporal.ZonedDateTime(0n, timeZone); +assert.sameValue(typeof datetime.toLocaleString(undefined, options), "string", "toLocaleString() with same options succeeds"); + +assert.throws(TypeError, () => formatter.format(datetime), "format() does not support Temporal.ZonedDateTime"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRange/temporal-zoneddatetime-not-supported.js b/test/intl402/DateTimeFormat/prototype/formatRange/temporal-zoneddatetime-not-supported.js new file mode 100644 index 0000000000..69e14c25b5 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRange/temporal-zoneddatetime-not-supported.js @@ -0,0 +1,18 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.datetimeformat.prototype.formatRangeToParts +description: Temporal.ZonedDateTime is not supported directly in formatRangeToParts() +features: [Temporal] +---*/ + +const formatter = new Intl.DateTimeFormat(); + +// Check that TypeError would not be thrown for a different reason +const {timeZone, ...options} = formatter.resolvedOptions(); +const datetime1 = new Temporal.ZonedDateTime(0n, timeZone); +assert.sameValue(typeof datetime1.toLocaleString(undefined, options), "string", "toLocaleString() with same options succeeds"); + +const datetime2 = new Temporal.ZonedDateTime(1_000_000_000n, timeZone); +assert.throws(TypeError, () => formatter.formatRangeToParts(datetime1, datetime2), "formatRangeToParts() does not support Temporal.ZonedDateTime"); diff --git a/test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-zoneddatetime-not-supported.js b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-zoneddatetime-not-supported.js new file mode 100644 index 0000000000..6a9fbdc1cb --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatRangeToParts/temporal-zoneddatetime-not-supported.js @@ -0,0 +1,18 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-intl.datetimeformat.prototype.formatRange +description: Temporal.ZonedDateTime is not supported directly in formatRange() +features: [Temporal] +---*/ + +const formatter = new Intl.DateTimeFormat(); + +// Check that TypeError would not be thrown for a different reason +const {timeZone, ...options} = formatter.resolvedOptions(); +const datetime1 = new Temporal.ZonedDateTime(0n, timeZone); +assert.sameValue(typeof datetime1.toLocaleString(undefined, options), "string", "toLocaleString() with same options succeeds"); + +const datetime2 = new Temporal.ZonedDateTime(1_000_000_000n, timeZone); +assert.throws(TypeError, () => formatter.formatRange(datetime1, datetime2), "formatRange() does not support Temporal.ZonedDateTime"); diff --git a/test/intl402/DateTimeFormat/prototype/formatToParts/temporal-zoneddatetime-not-supported.js b/test/intl402/DateTimeFormat/prototype/formatToParts/temporal-zoneddatetime-not-supported.js new file mode 100644 index 0000000000..5c65973f60 --- /dev/null +++ b/test/intl402/DateTimeFormat/prototype/formatToParts/temporal-zoneddatetime-not-supported.js @@ -0,0 +1,17 @@ +// Copyright (C) 2023 Igalia, S.L. All rights reserved. +// This code is governed by the BSD license found in the LICENSE file. + +/*--- +esid: sec-Intl.DateTimeFormat.prototype.formatToParts +description: Temporal.ZonedDateTime is not supported directly in formatToParts() +features: [Temporal] +---*/ + +const formatter = new Intl.DateTimeFormat(); + +// Check that TypeError would not be thrown for a different reason +const {timeZone, ...options} = formatter.resolvedOptions(); +const datetime = new Temporal.ZonedDateTime(0n, timeZone); +assert.sameValue(typeof datetime.toLocaleString(undefined, options), "string", "toLocaleString() with same options succeeds"); + +assert.throws(TypeError, () => formatter.formatToParts(datetime), "formatToParts() does not support Temporal.ZonedDateTime"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/calendar-mismatch.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/calendar-mismatch.js new file mode 100644 index 0000000000..1cb43bb4a2 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/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.zoneddatetime.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.ZonedDateTime(0n, "UTC", localeCalendar); +const result = sameCalendarInstance.toLocaleString(); +assert.sameValue(typeof result, "string", "toLocaleString() succeeds when instance has the same calendar as locale"); + +const isoInstance = new Temporal.ZonedDateTime(0n, "UTC", "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.ZonedDateTime(0n, "UTC", differentCalendar); +assert.throws(RangeError, () => differentCalendarInstance.toLocaleString(), "calendar mismatch"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/custom-time-zone-name-not-supported.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/custom-time-zone-name-not-supported.js new file mode 100644 index 0000000000..6c34b4b14b --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/custom-time-zone-name-not-supported.js @@ -0,0 +1,17 @@ +// 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.zoneddatetime.prototype.tolocalestring +description: > + Custom time zones with unofficial names are not supported for locale formatting +features: [Temporal] +---*/ + +const timeZone = { + id: "Etc/Custom_Zone", + getPossibleInstantsFor() {}, + getOffsetNanosecondsFor() {}, +}; +const datetime = new Temporal.ZonedDateTime(0n, timeZone); +assert.throws(RangeError, () => datetime.toLocaleString(), "Custom time zones with non-IANA identifiers not supported in Intl"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/locales-undefined.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/locales-undefined.js index 8ed6549fdf..560f8bd3e7 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/locales-undefined.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/locales-undefined.js @@ -8,8 +8,17 @@ features: [BigInt, Temporal] ---*/ const datetime = new Temporal.ZonedDateTime(957270896_987_650_000n, "UTC"); -const defaultFormatter = new Intl.DateTimeFormat([], Object.create(null)); -const expected = defaultFormatter.format(datetime); +const defaultFormatter = new Intl.DateTimeFormat([], { + year: "numeric", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + timeZoneName: "short", + timeZone: "UTC", +}); +const expected = defaultFormatter.format(datetime.toInstant()); const actualExplicit = datetime.toLocaleString(undefined); assert.sameValue(actualExplicit, expected, "default locale is determined by Intl.DateTimeFormat"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/offset-time-zone-not-supported.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/offset-time-zone-not-supported.js new file mode 100644 index 0000000000..032019140d --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/offset-time-zone-not-supported.js @@ -0,0 +1,11 @@ +// 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.zoneddatetime.prototype.tolocalestring +description: Offset time zones are not supported yet by Intl +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(0n, "+00:00"); +assert.throws(RangeError, () => datetime.toLocaleString(), "Intl.DateTimeFormat does not yet specify what to do with offset time zones"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZone.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZone.js new file mode 100644 index 0000000000..76dde5ae36 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZone.js @@ -0,0 +1,15 @@ +// 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.zoneddatetime.prototype.tolocalestring +description: > + Options must not have a timeZone property, even if it agrees with the + instance's time zone +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(0n, "UTC"); + +assert.throws(TypeError, () => datetime.toLocaleString("en-US", { timeZone: "Europe/Vienna" }), "timeZone option disallowed"); +assert.throws(TypeError, () => datetime.toLocaleString("en-US", { timeZone: "UTC" }), "timeZone option disallowed even if it agrees with instance's time zone"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZoneName-affects-instance-time-zone.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZoneName-affects-instance-time-zone.js new file mode 100644 index 0000000000..27cf3ba26f --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZoneName-affects-instance-time-zone.js @@ -0,0 +1,16 @@ +// 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.zoneddatetime.prototype.tolocalestring +description: timeZoneName option affects formatting of the instance's time zone +locale: [en-US] +features: [Temporal] +---*/ + +const datetime = new Temporal.ZonedDateTime(0n, "Europe/Vienna"); + +const resultShort = datetime.toLocaleString("en-US", { timeZoneName: "short" }); +const resultLong = datetime.toLocaleString("en-US", { timeZoneName: "long" }); +assert.notSameValue(resultShort, resultLong, "formats with different timeZoneName options should be different"); +assert(resultLong.includes("Central European Standard Time"), "time zone name can be written out in full"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-undefined.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-undefined.js index 64e3f7881d..b1c0a5b154 100644 --- a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-undefined.js +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-undefined.js @@ -8,8 +8,17 @@ features: [BigInt, Temporal] ---*/ const datetime = new Temporal.ZonedDateTime(957270896_987_650_000n, "UTC"); -const defaultFormatter = new Intl.DateTimeFormat('en', Object.create(null)); -const expected = defaultFormatter.format(datetime); +const defaultFormatter = new Intl.DateTimeFormat('en', { + year: "numeric", + month: "numeric", + day: "numeric", + hour: "numeric", + minute: "numeric", + second: "numeric", + timeZoneName: "short", + timeZone: "UTC", +}); +const expected = defaultFormatter.format(datetime.toInstant()); const actualExplicit = datetime.toLocaleString('en', undefined); assert.sameValue(actualExplicit, expected, "default locale is determined by Intl.DateTimeFormat"); diff --git a/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js new file mode 100644 index 0000000000..b1cc8b53b6 --- /dev/null +++ b/test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js @@ -0,0 +1,24 @@ +// 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.zoneddatetime.prototype.tolocalestring +description: Custom time zone names are canonicalized +features: [Temporal] +---*/ + +const timeZone1 = { + id: "Asia/Kolkata", + getPossibleInstantsFor() {}, + getOffsetNanosecondsFor() {}, +}; +const datetime1 = new Temporal.ZonedDateTime(0n, timeZone1); + +const timeZone2 = { + id: "Asia/Calcutta", + getPossibleInstantsFor() {}, + getOffsetNanosecondsFor() {}, +}; +const datetime2 = new Temporal.ZonedDateTime(0n, timeZone2); + +assert.sameValue(datetime1.toLocaleString(), datetime2.toLocaleString(), "Time zone names are canonicalized before passing to DateTimeFormat"); diff --git a/test/staging/Intl402/Temporal/old/date-time-format.js b/test/staging/Intl402/Temporal/old/date-time-format.js index e61e735175..25e7c6bc84 100644 --- a/test/staging/Intl402/Temporal/old/date-time-format.js +++ b/test/staging/Intl402/Temporal/old/date-time-format.js @@ -83,10 +83,6 @@ var end = new Date("1991-12-26"); 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${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${usDayPeriodSpace}PM`); assert.sameValue(at.format(Temporal.PlainDateTime.from(t1)), "18.11.1976, 14:23:30"); @@ -214,123 +210,6 @@ assert.deepEqual(at.formatToParts(Temporal.Instant.from(t2)), [ value: "56" } ]); -// should work for ZonedDateTime -assert.deepEqual(us2.formatToParts(Temporal.ZonedDateTime.from(t2)), [ - { - type: "month", - value: "2" - }, - { - type: "literal", - value: "/" - }, - { - type: "day", - value: "20" - }, - { - type: "literal", - value: "/" - }, - { - type: "year", - value: "2020" - }, - { - type: "literal", - value: ", " - }, - { - type: "hour", - value: "3" - }, - { - type: "literal", - value: ":" - }, - { - type: "minute", - value: "44" - }, - { - type: "literal", - value: ":" - }, - { - type: "second", - value: "56" - }, - { - type: "literal", - value: usDayPeriodSpace - }, - { - type: "dayPeriod", - value: "PM" - }, - { - type: "literal", - value: " " - }, - { - type: "timeZoneName", - value: "EST" - } -]); -assert.deepEqual(at2.formatToParts(Temporal.ZonedDateTime.from(t2)), [ - { - type: "day", - value: "20" - }, - { - type: "literal", - value: "." - }, - { - type: "month", - value: "2" - }, - { - type: "literal", - value: "." - }, - { - type: "year", - value: "2020" - }, - { - type: "literal", - value: ", " - }, - { - type: "hour", - value: "15" - }, - { - type: "literal", - value: ":" - }, - { - type: "minute", - value: "44" - }, - { - type: "literal", - value: ":" - }, - { - type: "second", - value: "56" - }, - { - type: "literal", - value: " " - }, - { - type: "timeZoneName", - value: "GMT-5" - } -]); // should work for DateTime assert.deepEqual(us.formatToParts(Temporal.PlainDateTime.from(t2)), [ { @@ -650,15 +529,6 @@ assert.sameValue( `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); -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)), @@ -725,9 +595,6 @@ assert.throws(RangeError, () => us.formatRange(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2).withCalendar("japanese")) ); -// throws for two ZonedDateTimes with different time zones -assert.throws(RangeError, () => us2.formatRange(Temporal.ZonedDateTime.from(t1), Temporal.ZonedDateTime.from(t2))); - // formatRangeToParts // should work for Instant assert.deepEqual(us.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Instant.from(t2)), [ @@ -984,304 +851,6 @@ assert.deepEqual(at.formatRangeToParts(Temporal.Instant.from(t1), Temporal.Insta source: "endRange" } ]); - -// should work for ZonedDateTime -var zdt1 = Temporal.ZonedDateTime.from(t1); -var zdt2 = Temporal.ZonedDateTime.from(t2).withTimeZone(zdt1); -assert.deepEqual(us2.formatRangeToParts(zdt1, zdt2), [ - { - type: "month", - value: "11", - source: "startRange" - }, - { - type: "literal", - value: "/", - source: "startRange" - }, - { - type: "day", - value: "18", - source: "startRange" - }, - { - type: "literal", - value: "/", - source: "startRange" - }, - { - type: "year", - value: "1976", - source: "startRange" - }, - { - type: "literal", - value: ", ", - source: "startRange" - }, - { - type: "hour", - value: "2", - source: "startRange" - }, - { - type: "literal", - value: ":", - source: "startRange" - }, - { - type: "minute", - value: "23", - source: "startRange" - }, - { - type: "literal", - value: ":", - source: "startRange" - }, - { - type: "second", - value: "30", - source: "startRange" - }, - { - type: "literal", - value: usDayPeriodSpace, - source: "startRange" - }, - { - type: "dayPeriod", - value: "PM", - source: "startRange" - }, - { - type: "literal", - value: " ", - source: "startRange" - }, - { - type: "timeZoneName", - value: "UTC", - source: "startRange" - }, - { - type: "literal", - value: usDateRangeSeparator, - source: "shared" - }, - { - type: "month", - value: "2", - source: "endRange" - }, - { - type: "literal", - value: "/", - source: "endRange" - }, - { - type: "day", - value: "20", - source: "endRange" - }, - { - type: "literal", - value: "/", - source: "endRange" - }, - { - type: "year", - value: "2020", - source: "endRange" - }, - { - type: "literal", - value: ", ", - source: "endRange" - }, - { - type: "hour", - value: "8", - source: "endRange" - }, - { - type: "literal", - value: ":", - source: "endRange" - }, - { - type: "minute", - value: "44", - source: "endRange" - }, - { - type: "literal", - value: ":", - source: "endRange" - }, - { - type: "second", - value: "56", - source: "endRange" - }, - { - type: "literal", - value: usDayPeriodSpace, - source: "endRange" - }, - { - type: "dayPeriod", - value: "PM", - source: "endRange" - }, - { - type: "literal", - value: " ", - source: "endRange" - }, - { - type: "timeZoneName", - value: "UTC", - source: "endRange" - } -]); -assert.deepEqual(at2.formatRangeToParts(zdt1, zdt2), [ - { - type: "day", - value: "18", - source: "startRange" - }, - { - type: "literal", - value: ".", - source: "startRange" - }, - { - type: "month", - value: "11", - source: "startRange" - }, - { - type: "literal", - value: ".", - source: "startRange" - }, - { - type: "year", - value: "1976", - source: "startRange" - }, - { - type: "literal", - value: ", ", - source: "startRange" - }, - { - type: "hour", - value: "14", - source: "startRange" - }, - { - type: "literal", - value: ":", - source: "startRange" - }, - { - type: "minute", - value: "23", - source: "startRange" - }, - { - type: "literal", - value: ":", - source: "startRange" - }, - { - type: "second", - value: "30", - source: "startRange" - }, - { - type: "literal", - value: " ", - source: "startRange" - }, - { - type: "timeZoneName", - value: "UTC", - source: "startRange" - }, - { - type: "literal", - value: deDateRangeSeparator, - source: "shared" - }, - { - type: "day", - value: "20", - source: "endRange" - }, - { - type: "literal", - value: ".", - source: "endRange" - }, - { - type: "month", - value: "2", - source: "endRange" - }, - { - type: "literal", - value: ".", - source: "endRange" - }, - { - type: "year", - value: "2020", - source: "endRange" - }, - { - type: "literal", - value: ", ", - source: "endRange" - }, - { - type: "hour", - value: "20", - source: "endRange" - }, - { - type: "literal", - value: ":", - source: "endRange" - }, - { - type: "minute", - value: "44", - source: "endRange" - }, - { - type: "literal", - value: ":", - source: "endRange" - }, - { - type: "second", - value: "56", - source: "endRange" - }, - { - type: "literal", - value: " ", - source: "endRange" - }, - { - type: "timeZoneName", - value: "UTC", - source: "endRange" - } -]); // should work for DateTime assert.deepEqual(us.formatRangeToParts(Temporal.PlainDateTime.from(t1), Temporal.PlainDateTime.from(t2)), [ { @@ -2094,7 +1663,3 @@ assert.throws(RangeError, () => assert.throws(RangeError, () => at.formatRangeToParts(Temporal.PlainDate.from(t1), Temporal.PlainDate.from(t2).withCalendar("japanese")) ); -// throws for two ZonedDateTimes with different time zones -assert.throws(RangeError, () => - us2.formatRangeToParts(Temporal.ZonedDateTime.from(t1), Temporal.ZonedDateTime.from(t2)) -); diff --git a/test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js b/test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js deleted file mode 100644 index b96dfeebc9..0000000000 --- a/test/staging/Intl402/Temporal/old/zoneddatetime-toLocaleString.js +++ /dev/null @@ -1,69 +0,0 @@ -// Copyright (C) 2018 Bloomberg LP. All rights reserved. -// This code is governed by the BSD license found in the LICENSE file. - -/*--- -esid: sec-temporal-zoneddatetime-objects -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 ( - ["era", "year", "month", "day", "hour", "minute", "second", "timeZoneName"].some( - (prop) => prop in fmt.resolvedOptions() - ) - ) { - // no weekday-only format available - return null; - } - return fmt; -} - -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${usDayPeriodSpace}PM GMT+1`); -assert.sameValue(zdt.toLocaleString("de-AT"), "18.11.1976, 15:23:30 MEZ"); - -const fmt = maybeGetWeekdayOnlyFormat(); -// uses only the options in resolvedOptions -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${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${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" })); - -// 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${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${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"); -assert.throws(RangeError, () => zdt.toLocaleString("en-US-u-ca-japanese"));