Skip to content

Commit d84937f

Browse files
committed
Normative: Add timeZoneName: "critical" option to ZonedDateTime.toString()
This adds a new recognized value "critical" to the timeZoneName option of ZonedDateTime.prototype.toString(). timeZoneName: "critical" behaves like timeZoneName: "always", but it also outputs a "!" flag in the time zone annotation. This flag is never used by Temporal, but could be consumed by other programs. See: #1450
1 parent e715a50 commit d84937f

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

docs/zoneddatetime.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ zdt1.equals(zdt1); // => true
12491249
Valid values are `'auto'` and `'never'`.
12501250
The default is `'auto'`.
12511251
- `timeZoneName` (string): Whether to show the time zone name annotation in the return value.
1252-
Valid values are `'auto'` and `'never'`.
1252+
Valid values are `'auto'`, `'never'`, and `'critical'`.
12531253
The default is `'auto'`.
12541254
- `calendarName` (string): Whether to show the calendar annotation in the return value.
12551255
Valid values are `'auto'`, `'always'`, `'never'`, and `'critical'`.
@@ -1288,8 +1288,9 @@ For more information on the calendar annotation, see [ISO string extensions](./s
12881288

12891289
Likewise, passing `'never'` to the `timeZoneName` or `offset` options controls whether the time zone offset (`+01:00`) or name annotation (`[Europe/Paris]`) are shown.
12901290
If the time zone offset is shown, it is always shown rounded to the nearest minute.
1291+
The `timeZoneName` option can additionally be `'critical'` which will add an additional `!` to the annotation, similar to `calendarName`.
12911292

1292-
The string format output by this method can be parsed by [`java.time.ZonedDateTime`](https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html) as long as the calendar annotation is not output.
1293+
The string format output by this method can be parsed by [`java.time.ZonedDateTime`](https://docs.oracle.com/javase/8/docs/api/java/time/ZonedDateTime.html) as long as the calendar annotation is not output and `'critical'` is not used.
12931294
For more information on `Temporal`'s extensions to the ISO 8601 / RFC 3339 string format and the progress towards becoming a published standard, see [String Parsing, Serialization, and Formatting](./strings.md).
12941295

12951296
Example usage:

polyfill/lib/ecmascript.mjs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,7 +710,7 @@ export const ES = ObjectAssign({}, ES2022, {
710710
return ES.GetOption(options, 'calendarName', ['auto', 'always', 'never', 'critical'], 'auto');
711711
},
712712
ToShowTimeZoneNameOption: (options) => {
713-
return ES.GetOption(options, 'timeZoneName', ['auto', 'never'], 'auto');
713+
return ES.GetOption(options, 'timeZoneName', ['auto', 'never', 'critical'], 'auto');
714714
},
715715
ToShowOffsetOption: (options) => {
716716
return ES.GetOption(options, 'offset', ['auto', 'never'], 'auto');
@@ -2151,7 +2151,10 @@ export const ES = ObjectAssign({}, ES2022, {
21512151
const offsetNs = ES.GetOffsetNanosecondsFor(tz, instant);
21522152
result += ES.FormatISOTimeZoneOffsetString(offsetNs);
21532153
}
2154-
if (showTimeZone !== 'never') result += `[${tz}]`;
2154+
if (showTimeZone !== 'never') {
2155+
const flag = showTimeZone === 'critical' ? '!' : '';
2156+
result += `[${flag}${tz}]`;
2157+
}
21552158
result += ES.MaybeFormatCalendarAnnotation(GetSlot(zdt, CALENDAR), showCalendar);
21562159
return result;
21572160
},

spec/abstractops.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ <h1>ToShowTimeZoneNameOption ( _normalizedOptions_ )</h1>
164164
It is different from the `timeZone` property passed to `Temporal.ZonedDateTime.from()` and from the `timeZone` property in the options passed to `Temporal.Instant.prototype.toString()`.
165165
</emu-note>
166166
<emu-alg>
167-
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, *"string"*, « *"auto"*, *"never"* », *"auto"*).
167+
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, *"string"*, « *"auto"*, *"never"*, *"critical"* », *"auto"*).
168168
</emu-alg>
169169
</emu-clause>
170170

spec/zoneddatetime.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1166,7 +1166,7 @@ <h1>
11661166
_zonedDateTime_: a Temporal.ZonedDateTime,
11671167
_precision_: one of *"auto"*, *"minute"*, or an integer between 0 and 9 inclusive,
11681168
_showCalendar_: one of *"auto"*, *"always"*, *"never"*, or *"critical"*,
1169-
_showTimeZone_: one of *"auto"* or *"never"*,
1169+
_showTimeZone_: one of *"auto"*, *"never"*, or *"critical"*,
11701170
_showOffset_: one of *"auto"* or *"never"*,
11711171
optional _increment_: an integer,
11721172
optional _unit_: one of *"minute"*, *"second"*, *"millisecond"*, *"microsecond"*, or *"nanosecond"*,
@@ -1198,7 +1198,8 @@ <h1>
11981198
1. Let _timeZoneString_ be the empty String.
11991199
1. Else,
12001200
1. Let _timeZoneID_ be ? ToString(_timeZone_).
1201-
1. Let _timeZoneString_ be the string-concatenation of the code unit 0x005B (LEFT SQUARE BRACKET), _timeZoneID_, and the code unit 0x005D (RIGHT SQUARE BRACKET).
1201+
1. If _showTimeZone_ is *"critical"*, let _flag_ be *"!"*; else let _flag_ be the empty String.
1202+
1. Let _timeZoneString_ be the string-concatenation of the code unit 0x005B (LEFT SQUARE BRACKET), _flag_, _timeZoneID_, and the code unit 0x005D (RIGHT SQUARE BRACKET).
12021203
1. Let _calendarString_ be ? MaybeFormatCalendarAnnotation(_zonedDateTime_.[[Calendar]], _showCalendar_).
12031204
1. Return the string-concatenation of _dateTimeString_, _offsetString_, _timeZoneString_, and _calendarString_.
12041205
</emu-alg>

0 commit comments

Comments
 (0)