-
Notifications
You must be signed in to change notification settings - Fork 464
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Temporal: Rewrite Temporal.ZonedDateTime.p.toLocaleString tests
In tc39/proposal-temporal#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.
- Loading branch information
Showing
14 changed files
with
202 additions
and
508 deletions.
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
test/intl402/DateTimeFormat/prototype/format/temporal-zoneddatetime-not-supported.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
18 changes: 18 additions & 0 deletions
18
test/intl402/DateTimeFormat/prototype/formatRange/temporal-zoneddatetime-not-supported.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
18 changes: 18 additions & 0 deletions
18
...tl402/DateTimeFormat/prototype/formatRangeToParts/temporal-zoneddatetime-not-supported.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
17 changes: 17 additions & 0 deletions
17
test/intl402/DateTimeFormat/prototype/formatToParts/temporal-zoneddatetime-not-supported.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
27 changes: 27 additions & 0 deletions
27
test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/calendar-mismatch.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
17 changes: 17 additions & 0 deletions
17
...02/Temporal/ZonedDateTime/prototype/toLocaleString/custom-time-zone-name-not-supported.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...intl402/Temporal/ZonedDateTime/prototype/toLocaleString/offset-time-zone-not-supported.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
15 changes: 15 additions & 0 deletions
15
test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/options-timeZone.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
16 changes: 16 additions & 0 deletions
16
...ZonedDateTime/prototype/toLocaleString/options-timeZoneName-affects-instance-time-zone.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
test/intl402/Temporal/ZonedDateTime/prototype/toLocaleString/time-zone-canonicalized.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); |
Oops, something went wrong.