From 3ddf26be53ae4320468e81965706c15063fa098b Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Sun, 1 Nov 2020 17:23:49 -0800 Subject: [PATCH] Rename ZonedDateTime.toString 'timeZone' option to 'timeZoneName' 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 --- docs/zoneddatetime.md | 4 ++-- polyfill/lib/ecmascript.mjs | 4 ++-- polyfill/lib/zoneddatetime.mjs | 2 +- polyfill/test/zoneddatetime.mjs | 14 +++++++------- spec/abstractops.html | 10 +++++----- spec/zoneddatetime.html | 2 +- 6 files changed, 18 insertions(+), 18 deletions(-) diff --git a/docs/zoneddatetime.md b/docs/zoneddatetime.md index 1214d18bff..baf47c8742 100644 --- a/docs/zoneddatetime.md +++ b/docs/zoneddatetime.md @@ -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. @@ -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). diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index 340bec7468..10afe63a46 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -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'); diff --git a/polyfill/lib/zoneddatetime.mjs b/polyfill/lib/zoneddatetime.mjs index 1a881b2cc9..3cf04a9fc0 100644 --- a/polyfill/lib/zoneddatetime.mjs +++ b/polyfill/lib/zoneddatetime.mjs @@ -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, diff --git a/polyfill/test/zoneddatetime.mjs b/polyfill/test/zoneddatetime.mjs index ca3af9c398..baf495910d 100644 --- a/polyfill/test/zoneddatetime.mjs +++ b/polyfill/test/zoneddatetime.mjs @@ -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]'); @@ -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) => diff --git a/spec/abstractops.html b/spec/abstractops.html index c6ba18835b..fe06ca8b41 100644 --- a/spec/abstractops.html +++ b/spec/abstractops.html @@ -187,17 +187,17 @@

ToShowCalendarOption ( _normalizedOptions_ )

- -

ToShowTimeZoneOption ( _normalizedOptions_ )

+ +

ToShowTimeZoneNameOption ( _normalizedOptions_ )

- 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.

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()`. - 1. Return ? GetOption(_normalizedOptions_, *"timeZone"*, *"string"*, « *"auto"*, *"never"* », *"auto"*). + 1. Return ? GetOption(_normalizedOptions_, *"timeZoneName"*, *"string"*, « *"auto"*, *"never"* », *"auto"*).
diff --git a/spec/zoneddatetime.html b/spec/zoneddatetime.html index e1cfacc2e7..4855640f74 100644 --- a/spec/zoneddatetime.html +++ b/spec/zoneddatetime.html @@ -726,7 +726,7 @@

Temporal.ZonedDateTime.prototype.toString ( [ _options_ ] )

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_).