Skip to content

Commit

Permalink
Temporal: Add tests for ZDT#toString timeZoneName: "critical" option
Browse files Browse the repository at this point in the history
See tc39/proposal-temporal#2397
This normative change adds a new accepted value for the timeZoneName
option in ZonedDateTime.prototype.toString().
  • Loading branch information
ptomato committed Oct 8, 2022
1 parent 07582cd commit 3f71a02
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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`);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit 3f71a02

Please sign in to comment.