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.

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:

Internal Slot | Property | Values |
---|---|---|

[[Weekday]] | ||

[[Era]] | ||

[[Year]] | ||

[[Month]] | ||

[[Day]] | ||

[[Hour]] | ||

[[Minute]] | ||

[[Second]] | ||

[[TimeZoneName]] |

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

- Let
`removalPenalty`be 120. - Let
`additionPenalty`be 20. - Let
`longLessPenalty`be 8. - Let
`longMorePenalty`be 6. - Let
`shortLessPenalty`be 6. - Let
`shortMorePenalty`be 3. - Let
`offsetPenalty`be 1. - Let
`bestScore`be -Infinity . - Let
`bestFormat`beundefined . Assert :Type (`formats`) isList .- For each element
`format`of`formats`, do- Let
`score`be 0. - For each
property name `property`shown inTable 1 , do- If
`options`has a field [[<`property`>]], let`optionsProp`be`options`.[[<`property`>]]; else let`optionsProp`beundefined . - If
`format`has a field [[<`property`>]], let`formatProp`be`format`.[[<`property`>]]; else let`formatProp`beundefined . - If
`optionsProp`isundefined and`formatProp`is notundefined , decrease`score`by`additionPenalty`. - Else if
`optionsProp`is notundefined and`formatProp`isundefined , decrease`score`by`removalPenalty`. - Else if
`property`is"timeZoneName" , then- If
`optionsProp`is"short" or"shortGeneric" , then- If
`formatProp`is"shortOffset" , decrease`score`by`offsetPenalty`. - Else if
`formatProp`is"longOffset" , decrease`score`by (`offsetPenalty`+`shortMorePenalty`). - Else if
`optionsProp`is"short" and`formatProp`is"long" , decrease`score`by`shortMorePenalty`. - Else if
`optionsProp`is"shortGeneric" and`formatProp`is"longGeneric" , decrease`score`by`shortMorePenalty`. - Else if
`optionsProp`≠`formatProp`, decrease`score`by`removalPenalty`.

- If
- Else if
`optionsProp`is"shortOffset" and`formatProp`is"longOffset" , decrease`score`by`shortMorePenalty`. - Else if
`optionsProp`is"long" or"longGeneric" , then- If
`formatProp`is"longOffset" , decrease`score`by`offsetPenalty`. - Else if
`formatProp`is"shortOffset" , decrease`score`by (`offsetPenalty`+`longLessPenalty`). - Else if
`optionsProp`is"long" and`formatProp`is"short" , decrease`score`by`longLessPenalty`. - Else if
`optionsProp`is"longGeneric" and`formatProp`is"shortGeneric" , decrease`score`by`longLessPenalty`. - Else if
`optionsProp`≠`formatProp`, decrease`score`by`removalPenalty`.

- If
- Else if
`optionsProp`is"longOffset" and`formatProp`is"shortOffset" , decrease`score`by`longLessPenalty`. - Else if
`optionsProp`≠`formatProp`, decrease`score`by`removalPenalty`.

- If
- Else if
`optionsProp`≠`formatProp`, then- If
`property`is"fractionalSecondDigits" , then- Let
`values`be «1 _{𝔽},2 _{𝔽},3 _{𝔽}».

- Let
- Else,
- Let
`values`be «"2-digit" ,"numeric" ,"narrow" ,"short" ,"long" ».

- Let
- Let
`optionsPropIndex`be the index of`optionsProp`within`values`. - Let
`formatPropIndex`be the index of`formatProp`within`values`. - Let
`delta`bemax (min (`formatPropIndex`-`optionsPropIndex`, 2), -2). - If
`delta`= 2, decrease`score`by`longMorePenalty`. - Else if
`delta`= 1, decrease`score`by`shortMorePenalty`. - Else if
`delta`= -1, decrease`score`by`shortLessPenalty`. - Else if
`delta`= -2, decrease`score`by`longLessPenalty`.

- If

- If
- If
`score`>`bestScore`, then- Let
`bestScore`be`score`. - Let
`bestFormat`be`format`.

- Let

- Let
- Return
`bestFormat`.

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 `rangeFormatOptions` (which is a range pattern `x` as a `pattern` and to the effective locale and the formatting options of `dateTimeFormat` and `rangeFormatOptions`. The following steps are taken:

- Let
`x`beTimeClip (`x`). - If
`x`isNaN , throw aRangeError exception. - Let
`locale`be`dateTimeFormat`.[[Locale]]. - Let
`nfOptions`beOrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (`nfOptions`,"useGrouping" ,false ). - Let
`nf`be ?Construct (%NumberFormat%, «`locale`,`nfOptions`»). - Let
`nf2Options`beOrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (`nf2Options`,"minimumIntegerDigits" , 2). - Perform !
CreateDataPropertyOrThrow (`nf2Options`,"useGrouping" ,false ). - Let
`nf2`be ?Construct (%NumberFormat%, «`locale`,`nf2Options`»). - Let
`fractionalSecondDigits`be`dateTimeFormat`.[[FractionalSecondDigits]]. - If
`fractionalSecondDigits`is notundefined , then- Let
`nf3Options`beOrdinaryObjectCreate (null ). - Perform !
CreateDataPropertyOrThrow (`nf3Options`,"minimumIntegerDigits" ,`fractionalSecondDigits`). - Perform !
CreateDataPropertyOrThrow (`nf3Options`,"useGrouping" ,false ). - Let
`nf3`be ?Construct (%NumberFormat%, «`locale`,`nf3Options`»).

- Let
- Let
`tm`beToLocalTime (`x`,`dateTimeFormat`.[[Calendar]],`dateTimeFormat`.[[TimeZone]]). - Let
`result`be a new emptyList . - For each
Record { [[Type]], [[Value]] }`patternPart`in`patternParts`, do- Let
`p`be`patternPart`.[[Type]]. - If
`p`is"literal" , then- Append a new
Record { [[Type]]:"literal" , [[Value]]:`patternPart`.[[Value]] } as the last element of the list`result`.

- Append a new
- Else if
`p`is equal to"fractionalSecondDigits" , then- Let
`v`be`tm`.[[Millisecond]]. - Let
`v`befloor (`v`× 10^{( fractionalSecondDigits - 3 )}). - Let
`fv`beFormatNumeric (`nf3`,`v`). - Append a new
Record { [[Type]]:"fractionalSecond" , [[Value]]:`fv`} as the last element of`result`.

- Let
- Else if
`p`is equal to"dayPeriod" , then- Let
`f`be the value of`dateTimeFormat`'s internal slot whose name is the Internal Slot column of the matching row. - 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`. - Append a new
Record { [[Type]]:`p`, [[Value]]:`fv`} as the last element of the list`result`.

- Let
- Else if
`p`is equal to"timeZoneName" , then- Let
`f`be`dateTimeFormat`.[[TimeZoneName]]. - Let
`v`be`dateTimeFormat`.[[TimeZone]]. - 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. - Append a new
Record { [[Type]]:`p`, [[Value]]:`fv`} as the last element of the list`result`.

- Let
- Else if
`p`matches a Property column of the row inTable 1 , then- If
`rangeFormatOptions`is notundefined , let`f`be the value of`rangeFormatOptions`'s field whose name matches`p`. - Else, let
`f`be the value of`dateTimeFormat`'s internal slot whose name is the Internal Slot column of the matching row. - Let
`v`be the value of`tm`'s field whose name is the Internal Slot column of the matching row. - If
`p`is"year" and`v`≤ 0, let`v`be 1 -`v`. - If
`p`is"month" , increase`v`by 1. - If
`p`is"hour" and`dateTimeFormat`.[[HourCycle]] is"h11" or"h12" , then- Let
`v`be`v`modulo 12. - If
`v`is 0 and`dateTimeFormat`.[[HourCycle]] is"h12" , let`v`be 12.

- Let
- If
`p`is"hour" and`dateTimeFormat`.[[HourCycle]] is"h24" , then- If
`v`is 0, let`v`be 24.

- If
- If
`f`is"numeric" , then- Let
`fv`beFormatNumeric (`nf`,`v`).

- Let
- Else if
`f`is"2-digit" , then- Let
`fv`beFormatNumeric (`nf2`,`v`). - If the
"length" property of`fv`is greater than 2, let`fv`be the substring of`fv`containing the last two characters.

- Let
- 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`isundefined , then the String value may also depend on whether`dateTimeFormat`.[[Day]] isundefined . If`p`is"month" and`rangeFormatOptions`is notundefined , then the String value may also depend on whether`rangeFormatOptions`.[[day]] isundefined .~~If~~If`p`is"timeZoneName" , then the String value may also depend on the value of the [[InDST]] field of`tm`.`p`is"era" and`rangeFormatOptions`isundefined , then the String value may also depend on whether`dateTimeFormat`.[[Era]] isundefined . If`p`is"era" and`rangeFormatOptions`is notundefined , then the String value may also depend on whether`rangeFormatOptions`.[[era]] isundefined . If the implementation does not have a localized representation of`f`, then use the String value of`v`itself. - Append a new
Record { [[Type]]:`p`, [[Value]]:`fv`} as the last element of the list`result`.

- If
- Else if
`p`is equal to"ampm" , then- Let
`v`be`tm`.[[Hour]]. - If
`v`is greater than 11, then- Let
`fv`be an implementation and locale dependent String value representing"post meridiem" .

- Let
- Else,
- Let
`fv`be an implementation and locale dependent String value representing"ante meridiem" .

- Let
- Append a new
Record { [[Type]]:"dayPeriod" , [[Value]]:`fv`} as the last element of the list`result`.

- Let
- Else if
`p`is equal to"relatedYear" , then- Let
`v`be`tm`.[[RelatedYear]]. - Let
`fv`beFormatNumeric (`nf`,`v`). - Append a new
Record { [[Type]]:"relatedYear" , [[Value]]:`fv`} as the last element of the list`result`.

- Let
- Else if
`p`is equal to"yearName" , then- Let
`v`be`tm`.[[YearName]]. - Let
`fv`be an implementation and locale dependent String value representing`v`. - Append a new
Record { [[Type]]:"yearName" , [[Value]]:`fv`} as the last element of the list`result`.

- Let
- Else,
- Let
`unknown`be an implementation-, locale-, and numbering system-dependent String based on`x`and`p`. - Append a new
Record { [[Type]]:"unknown" , [[Value]]:`unknown`} as the last element of`result`.

- Let

- Let
- Return
`result`.

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.

It is recommended that implementations use the time zone information of the IANA Time Zone Database.

© 2021 Google, Ecma International

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:

- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- 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.
- 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.