Temporal: Add tests for ZDT#toString timeZoneName: "critical" option

See https://github.com/tc39/proposal-temporal/pull/2397
This normative change adds a new accepted value for the timeZoneName
option in ZonedDateTime.prototype.toString().
This commit is contained in:
Philip Chimento 2022-10-07 18:28:31 -07:00 committed by Ms2ger
parent d5404f4d24
commit 6205eb529d
4 changed files with 28 additions and 3 deletions

View File

@ -0,0 +1,25 @@
// Copyright (C) 2022 Igalia, S.L. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.
/*---
esid: sec-temporal.zoneddatetime.prototype.tostring
description: >
If timeZoneName is "auto", the time zone ID should be included and prefixed
with "!"
features: [Temporal]
---*/
const tests = [
["UTC", "1970-01-01T01:01:01.987654321+00:00[!UTC]", "built-in UTC"],
["+01:00", "1970-01-01T02:01:01.987654321+01:00[!+01:00]", "built-in offset"],
[{
getOffsetNanosecondsFor() { return 0; },
toString() { return "Etc/Custom"; },
}, "1970-01-01T01:01:01.987654321+00:00[!Etc/Custom]", "custom"],
];
for (const [timeZone, expected, description] of tests) {
const date = new Temporal.ZonedDateTime(3661_987_654_321n, timeZone);
const result = date.toString({ timeZoneName: "critical" });
assert.sameValue(result, expected, `${description} time zone for timeZoneName = critical`);
}

View File

@ -8,7 +8,7 @@ info: |
sec-getoption step 10:
10. If _values_ is not *undefined* and _values_ does not contain an element equal to _value_, throw a *RangeError* exception.
sec-temporal-toshowtimezonenameoption step 1:
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, « String », « *"auto"*, *"never"* », *"auto"*).
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, « *"string"* », « *"auto"*, *"never"*, *"critical"* », *"auto"*).
sec-temporal.zoneddatetime.protoype.tostring step 7:
7. Let _showTimeZone_ be ? ToShowTimeZoneNameOption(_options_).
features: [Temporal]

View File

@ -8,7 +8,7 @@ info: |
sec-getoption step 3:
3. If _value_ is *undefined*, return _fallback_.
sec-temporal-toshowtimezonenameoption step 1:
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, « String », « *"auto"*, *"never"* », *"auto"*).
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, « *"string"* », « *"auto"*, *"never"*, *"critical"* », *"auto"*).
sec-temporal.zoneddatetime.protoype.tostring step 7:
7. Let _showTimeZone_ be ? ToShowTimeZoneNameOption(_options_).
features: [Temporal]

View File

@ -8,7 +8,7 @@ info: |
sec-getoption step 9.a:
a. Set _value_ to ? ToString(_value_).
sec-temporal-toshowtimezonenameoption step 1:
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, « String », « *"auto"*, *"never"* », *"auto"*).
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, « *"string"* », « *"auto"*, *"never"*, *"critical"* », *"auto"*).
sec-temporal.zoneddatetime.protoype.tostring step 7:
7. Let _showTimeZone_ be ? ToShowTimeZoneNameOption(_options_).
includes: [compareArray.js, temporalHelpers.js]