Skip to content

Commit

Permalink
Rename ZonedDateTime.toString 'timeZone' option to 'timeZoneName'
Browse files Browse the repository at this point in the history
I've taken the liberty of renaming this, otherwise it has a conflicting
meaning compared with the 'timeZone' option passed to Instant.toString()
(which will be added in #741.)

Making the distinction between 'timeZone' and 'timeZoneName' in this way
aligns exactly with what Intl.DateTimeFormat does.

See: #703
  • Loading branch information
ptomato committed Nov 2, 2020
1 parent e5389e2 commit 3ddf26b
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 18 deletions.
4 changes: 2 additions & 2 deletions docs/zoneddatetime.md
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,7 @@ zdt1.equals(zdt1); // => true
- `offset` (string): Whether to show the time zone offset in the return value.
Valid values are `'auto'` and `'never'`.
The default is `'auto'`.
- `timeZone` (string): Whether to show the time zone name annotation in the return value.
- `timeZoneName` (string): Whether to show the time zone name annotation in the return value.
Valid values are `'auto'` and `'never'`.
The default is `'auto'`.
- `calendar` (string): Whether to show the calendar annotation in the return value.
Expand Down Expand Up @@ -1118,7 +1118,7 @@ Normally, a calendar annotation is shown when `zonedDateTime`'s calendar is not
By setting the `calendar` option to `'always'` or `'never'` this can be overridden to always or never show the annotation, respectively.
For more information on the calendar annotation, see [ISO string extensions](./iso-string-ext.md#calendar-systems).
Likewise, passing `'never'` to the `timeZone` or `offset` options controls whether the time zone offset (`+01:00`) or name annotation (`[Europe/Paris]`) are shown.
Likewise, passing `'never'` to the `timeZoneName` or `offset` options controls whether the time zone offset (`+01:00`) or name annotation (`[Europe/Paris]`) are shown.
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.
For more information on `Temporal`'s extensions to the ISO string format and the progress towards becoming a published standard, see [ISO standard extensions](./iso-string-ext.md).
Expand Down
4 changes: 2 additions & 2 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -472,8 +472,8 @@ export const ES = ObjectAssign({}, ES2020, {
ToShowCalendarOption: (options) => {
return ES.GetOption(options, 'calendar', ['auto', 'always', 'never'], 'auto');
},
ToShowTimeZoneOption: (options) => {
return ES.GetOption(options, 'timeZone', ['auto', 'never'], 'auto');
ToShowTimeZoneNameOption: (options) => {
return ES.GetOption(options, 'timeZoneName', ['auto', 'never'], 'auto');
},
ToShowOffsetOption: (options) => {
return ES.GetOption(options, 'offset', ['auto', 'never'], 'auto');
Expand Down
2 changes: 1 addition & 1 deletion polyfill/lib/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ export class ZonedDateTime {
const { precision, unit, increment } = ES.ToSecondsStringPrecision(options);
const roundingMode = ES.ToTemporalRoundingMode(options, 'trunc');
const showCalendar = ES.ToShowCalendarOption(options);
const showTimeZone = ES.ToShowTimeZoneOption(options);
const showTimeZone = ES.ToShowTimeZoneNameOption(options);
const showOffset = ES.ToShowOffsetOption(options);
return zonedDateTimeToString(this, precision, showCalendar, showTimeZone, showOffset, {
unit,
Expand Down
14 changes: 7 additions & 7 deletions polyfill/test/zoneddatetime.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -366,11 +366,11 @@ describe('ZonedDateTime', () => {
throws(() => zdt1.toString({ calendar }), RangeError);
});
});
it('shows time zone if timeZone = auto', () => {
equal(zdt1.toString({ timeZone: 'auto' }), '1976-11-18T15:23:00+01:00[Europe/Vienna]');
it('shows time zone if timeZoneName = auto', () => {
equal(zdt1.toString({ timeZoneName: 'auto' }), '1976-11-18T15:23:00+01:00[Europe/Vienna]');
});
it('omits time zone if timeZone = never', () => {
equal(zdt1.toString({ timeZone: 'never' }), '1976-11-18T15:23:00+01:00');
it('omits time zone if timeZoneName = never', () => {
equal(zdt1.toString({ timeZoneName: 'never' }), '1976-11-18T15:23:00+01:00');
});
it('shows offset if offset = auto', () => {
equal(zdt1.toString({ offset: 'auto' }), '1976-11-18T15:23:00+01:00[Europe/Vienna]');
Expand All @@ -380,10 +380,10 @@ describe('ZonedDateTime', () => {
});
it('combinations of calendar, time zone, and offset', () => {
const zdt = zdt1.withCalendar('gregory');
equal(zdt.toString({ timeZone: 'never', calendar: 'never' }), '1976-11-18T15:23:00+01:00');
equal(zdt.toString({ timeZoneName: 'never', calendar: 'never' }), '1976-11-18T15:23:00+01:00');
equal(zdt.toString({ offset: 'never', calendar: 'never' }), '1976-11-18T15:23:00[Europe/Vienna]');
equal(zdt.toString({ offset: 'never', timeZone: 'never' }), '1976-11-18T15:23:00[c=gregory]');
equal(zdt.toString({ offset: 'never', timeZone: 'never', calendar: 'never' }), '1976-11-18T15:23:00');
equal(zdt.toString({ offset: 'never', timeZoneName: 'never' }), '1976-11-18T15:23:00[c=gregory]');
equal(zdt.toString({ offset: 'never', timeZoneName: 'never', calendar: 'never' }), '1976-11-18T15:23:00');
});
it('truncates to minute', () => {
[zdt1, zdt2, zdt3].forEach((zdt) =>
Expand Down
10 changes: 5 additions & 5 deletions spec/abstractops.html
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,17 @@ <h1>ToShowCalendarOption ( _normalizedOptions_ )</h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-toshowtimezoneoption" aoid="ToShowTimeZoneOption">
<h1>ToShowTimeZoneOption ( _normalizedOptions_ )</h1>
<emu-clause id="sec-temporal-toshowtimezonenameoption" aoid="ToShowTimeZoneNameOption">
<h1>ToShowTimeZoneNameOption ( _normalizedOptions_ )</h1>
<p>
The abstract operation ToShowTimeZoneOption extracts the value of the property named *"timeZone"* from _normalizedOptions_ and makes sure it is a valid value for the option.
The abstract operation ToShowTimeZoneNameOption extracts the value of the property named *"timeZoneName"* from _normalizedOptions_ and makes sure it is a valid value for the option.
</p>
<emu-note>
This property is used in `Temporal.ZonedDateTime.prototype.toString()`.
It is different from the `timeZone` property passed to `Temporal.ZonedDateTime.from()`.
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()`.
</emu-note>
<emu-alg>
1. Return ? GetOption(_normalizedOptions_, *"timeZone"*, *"string"*, « *"auto"*, *"never"* », *"auto"*).
1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, *"string"*, « *"auto"*, *"never"* », *"auto"*).
</emu-alg>
</emu-clause>

Expand Down
2 changes: 1 addition & 1 deletion spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ <h1>Temporal.ZonedDateTime.prototype.toString ( [ _options_ ] )</h1>
1. Let _precision_ be ? ToSecondsStringPrecision(_options_).
1. Let _roundingMode_ be ? ToTemporalRoundingMode(_options_, *"trunc"*).
1. Let _showCalendar_ be ? ToShowCalendarOption(_options_).
1. Let _showTimeZone_ be ? ToShowTimeZoneOption(_options_).
1. Let _showTimeZone_ be ? ToShowTimeZoneNameOption(_options_).
1. Let _showOffset_ be ? ToShowOffsetOption(_options_).
1. Return ? TemporalZonedDateTimeToString(_zonedDateTime_, _precision_.[[Precision]], _showCalendar_, _showTimeZone, _showOffset_, _precision_.[[Increment]], _precision_.[[Unit]], _roundingMode_).
</emu-alg>
Expand Down

0 comments on commit 3ddf26b

Please sign in to comment.