Stage 3 Draft / July 3, 2021

Extend TimeZoneName Option Proposal

Introduction

This proposal adds several valid values for the timeZoneName option to Intl.DateTimeFormat. These values of timeZoneName empower web developers to format time with additional common used timezone representations. See the README for more context.

1 DateTimeFormat Objects

1.1 Abstract Operations For DateTimeFormat Objects

Several DateTimeFormat algorithms use values from the following table, which provides internal slots, property names and allowable values for the components of date and time formats:

Table 1: Components of date and time formats
Internal Slot Property Values
[[Weekday]] "weekday" "narrow", "short", "long"
[[Era]] "era" "narrow", "short", "long"
[[Year]] "year" "2-digit", "numeric"
[[Month]] "month" "2-digit", "numeric", "narrow", "short", "long"
[[Day]] "day" "2-digit", "numeric"
[[Hour]] "hour" "2-digit", "numeric"
[[Minute]] "minute" "2-digit", "numeric"
[[Second]] "second" "2-digit", "numeric"
[[TimeZoneName]] "timeZoneName" "short", "long", "shortOffset", "longOffset", "shortGeneric", "longGeneric"

1.1.1 BasicFormatMatcher ( options, formats )

When the BasicFormatMatcher abstract operation is called with two arguments options and formats, the following steps are taken:

  1. Let removalPenalty be 120.
  2. Let additionPenalty be 20.
  3. Let longLessPenalty be 8.
  4. Let longMorePenalty be 6.
  5. Let shortLessPenalty be 6.
  6. Let shortMorePenalty be 3.
  7. Let offsetPenalty be 1.
  8. Let bestScore be -Infinity.
  9. Let bestFormat be undefined.
  10. Assert: Type(formats) is List.
  11. For each element format of formats, do
    1. Let score be 0.
    2. For each property name property shown in Table 1, do
      1. If options has a field [[<property>]], let optionsProp be options.[[<property>]]; else let optionsProp be undefined.
      2. If format has a field [[<property>]], let formatProp be format.[[<property>]]; else let formatProp be undefined.
      3. If optionsProp is undefined and formatProp is not undefined, decrease score by additionPenalty.
      4. Else if optionsProp is not undefined and formatProp is undefined, decrease score by removalPenalty.
      5. Else if property is "timeZoneName", then
        1. If optionsProp is "short" or "shortGeneric", then
          1. If formatProp is "shortOffset", decrease score by offsetPenalty.
          2. Else if formatProp is "longOffset", decrease score by (offsetPenalty + shortMorePenalty).
          3. Else if optionsProp is "short" and formatProp is "long", decrease score by shortMorePenalty.
          4. Else if optionsProp is "shortGeneric" and formatProp is "longGeneric", decrease score by shortMorePenalty.
          5. Else if optionsPropformatProp, decrease score by removalPenalty.
        2. Else if optionsProp is "shortOffset" and formatProp is "longOffset", decrease score by shortMorePenalty.
        3. Else if optionsProp is "long" or "longGeneric", then
          1. If formatProp is "longOffset", decrease score by offsetPenalty.
          2. Else if formatProp is "shortOffset", decrease score by (offsetPenalty + longLessPenalty).
          3. Else if optionsProp is "long" and formatProp is "short", decrease score by longLessPenalty.
          4. Else if optionsProp is "longGeneric" and formatProp is "shortGeneric", decrease score by longLessPenalty.
          5. Else if optionsPropformatProp, decrease score by removalPenalty.
        4. Else if optionsProp is "longOffset" and formatProp is "shortOffset", decrease score by longLessPenalty.
        5. Else if optionsPropformatProp, decrease score by removalPenalty.
      6. Else if optionsPropformatProp, then
        1. If property is "fractionalSecondDigits", then
          1. Let values be « 1𝔽, 2𝔽, 3𝔽 ».
        2. Else,
          1. Let values be « "2-digit", "numeric", "narrow", "short", "long" ».
        3. Let optionsPropIndex be the index of optionsProp within values.
        4. Let formatPropIndex be the index of formatProp within values.
        5. Let delta be max(min(formatPropIndex - optionsPropIndex, 2), -2).
        6. If delta = 2, decrease score by longMorePenalty.
        7. Else if delta = 1, decrease score by shortMorePenalty.
        8. Else if delta = -1, decrease score by shortLessPenalty.
        9. Else if delta = -2, decrease score by longLessPenalty.
    3. If score > bestScore, then
      1. Let bestScore be score.
      2. Let bestFormat be format.
  12. Return bestFormat.

1.1.2 FormatDateTimePattern ( dateTimeFormat, patternParts, x, rangeFormatOptions )

The FormatDateTimePattern abstract operation is called with arguments dateTimeFormat (which must be an object initialized as a DateTimeFormat), patternParts (which is a list of Records as returned by PartitionPattern), x (which must be a Number value), and rangeFormatOptions (which is a range pattern Record as used in [[rangePattern]] or undefined), interprets x as a time value as specified in es2022, 20.4.1.1, and creates the corresponding parts according pattern and to the effective locale and the formatting options of dateTimeFormat and rangeFormatOptions. The following steps are taken:

  1. Let x be TimeClip(x).
  2. If x is NaN, throw a RangeError exception.
  3. Let locale be dateTimeFormat.[[Locale]].
  4. Let nfOptions be OrdinaryObjectCreate(null).
  5. Perform ! CreateDataPropertyOrThrow(nfOptions, "useGrouping", false).
  6. Let nf be ? Construct(%NumberFormat%, « locale, nfOptions »).
  7. Let nf2Options be OrdinaryObjectCreate(null).
  8. Perform ! CreateDataPropertyOrThrow(nf2Options, "minimumIntegerDigits", 2).
  9. Perform ! CreateDataPropertyOrThrow(nf2Options, "useGrouping", false).
  10. Let nf2 be ? Construct(%NumberFormat%, « locale, nf2Options »).
  11. Let fractionalSecondDigits be dateTimeFormat.[[FractionalSecondDigits]].
  12. If fractionalSecondDigits is not undefined, then
    1. Let nf3Options be OrdinaryObjectCreate(null).
    2. Perform ! CreateDataPropertyOrThrow(nf3Options, "minimumIntegerDigits", fractionalSecondDigits).
    3. Perform ! CreateDataPropertyOrThrow(nf3Options, "useGrouping", false).
    4. Let nf3 be ? Construct(%NumberFormat%, « locale, nf3Options »).
  13. Let tm be ToLocalTime(x, dateTimeFormat.[[Calendar]], dateTimeFormat.[[TimeZone]]).
  14. Let result be a new empty List.
  15. For each Record { [[Type]], [[Value]] } patternPart in patternParts, do
    1. Let p be patternPart.[[Type]].
    2. If p is "literal", then
      1. Append a new Record { [[Type]]: "literal", [[Value]]: patternPart.[[Value]] } as the last element of the list result.
    3. Else if p is equal to "fractionalSecondDigits", then
      1. Let v be tm.[[Millisecond]].
      2. Let v be floor(v × 10( fractionalSecondDigits - 3 )).
      3. Let fv be FormatNumeric(nf3, v).
      4. Append a new Record { [[Type]]: "fractionalSecond", [[Value]]: fv } as the last element of result.
    4. Else if p is equal to "dayPeriod", then
      1. Let f be the value of dateTimeFormat's internal slot whose name is the Internal Slot column of the matching row.
      2. Let fv be a String value representing the day period of tm in the form given by f; the String value depends upon the implementation and the effective locale of dateTimeFormat.
      3. Append a new Record { [[Type]]: p, [[Value]]: fv } as the last element of the list result.
    5. Else if p is equal to "timeZoneName", then
      1. Let f be dateTimeFormat.[[TimeZoneName]].
      2. Let v be dateTimeFormat.[[TimeZone]].
      3. Let fv be a String value representing v in the form given by f; the String value depends upon the implementation and the effective locale of dateTimeFormat. The String value may also depend on the value of the [[InDST]] field of tm if f is "short", "long", "shortOffset", or "longOffset". If the implementation does not have a localized representation of f, then use the String value of v itself.
      4. Append a new Record { [[Type]]: p, [[Value]]: fv } as the last element of the list result.
    6. Else if p matches a Property column of the row in Table 1, then
      1. If rangeFormatOptions is not undefined, let f be the value of rangeFormatOptions's field whose name matches p.
      2. Else, let f be the value of dateTimeFormat's internal slot whose name is the Internal Slot column of the matching row.
      3. Let v be the value of tm's field whose name is the Internal Slot column of the matching row.
      4. If p is "year" and v ≤ 0, let v be 1 - v.
      5. If p is "month", increase v by 1.
      6. If p is "hour" and dateTimeFormat.[[HourCycle]] is "h11" or "h12", then
        1. Let v be v modulo 12.
        2. If v is 0 and dateTimeFormat.[[HourCycle]] is "h12", let v be 12.
      7. If p is "hour" and dateTimeFormat.[[HourCycle]] is "h24", then
        1. If v is 0, let v be 24.
      8. If f is "numeric", then
        1. Let fv be FormatNumeric(nf, v).
      9. Else if f is "2-digit", then
        1. Let fv be FormatNumeric(nf2, v).
        2. If the "length" property of fv is greater than 2, let fv be the substring of fv containing the last two characters.
      10. Else if f is "narrow", "short", or "long", then let fv be a String value representing v in the form given by f; the String value depends upon the implementation and the effective locale and calendar of dateTimeFormat. If p is "month" and rangeFormatOptions is undefined, then the String value may also depend on whether dateTimeFormat.[[Day]] is undefined. If p is "month" and rangeFormatOptions is not undefined, then the String value may also depend on whether rangeFormatOptions.[[day]] is undefined. If p is "timeZoneName", then the String value may also depend on the value of the [[InDST]] field of tm. If p is "era" and rangeFormatOptions is undefined, then the String value may also depend on whether dateTimeFormat.[[Era]] is undefined. If p is "era" and rangeFormatOptions is not undefined, then the String value may also depend on whether rangeFormatOptions.[[era]] is undefined. If the implementation does not have a localized representation of f, then use the String value of v itself.
      11. Append a new Record { [[Type]]: p, [[Value]]: fv } as the last element of the list result.
    7. Else if p is equal to "ampm", then
      1. Let v be tm.[[Hour]].
      2. If v is greater than 11, then
        1. Let fv be an implementation and locale dependent String value representing "post meridiem".
      3. Else,
        1. Let fv be an implementation and locale dependent String value representing "ante meridiem".
      4. Append a new Record { [[Type]]: "dayPeriod", [[Value]]: fv } as the last element of the list result.
    8. Else if p is equal to "relatedYear", then
      1. Let v be tm.[[RelatedYear]].
      2. Let fv be FormatNumeric(nf, v).
      3. Append a new Record { [[Type]]: "relatedYear", [[Value]]: fv } as the last element of the list result.
    9. Else if p is equal to "yearName", then
      1. Let v be tm.[[YearName]].
      2. Let fv be an implementation and locale dependent String value representing v.
      3. Append a new Record { [[Type]]: "yearName", [[Value]]: fv } as the last element of the list result.
    10. Else,
      1. Let unknown be an implementation-, locale-, and numbering system-dependent String based on x and p.
      2. Append a new Record { [[Type]]: "unknown", [[Value]]: unknown } as the last element of result.
  16. Return result.
Note 1
It is recommended that implementations use the locale and calendar dependent strings provided by the Common Locale Data Repository (available at http://cldr.unicode.org), and use CLDR "abbreviated" strings for DateTimeFormat "short" strings, and CLDR "wide" strings for DateTimeFormat "long" strings.
Note 2
It is recommended that implementations use the time zone information of the IANA Time Zone Database.

A Copyright & Software License

Copyright Notice

© 2021 Google, Ecma International

Software License

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT https://ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  3. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.