├── .travis.yml ├── README.md ├── biblio.json ├── deploy.sh ├── github_deploy_key.enc ├── package.json └── spec.html /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: off 2 | 3 | language: node_js 4 | 5 | node_js: 6 | - stable 7 | 8 | script: 9 | - bash ./deploy.sh 10 | 11 | env: 12 | global: 13 | - ENCRYPTION_LABEL: "856fa5c47e24" 14 | - GH_USER_NAME: "littledan" 15 | - GH_USER_EMAIL: "littledan@igalia.com" 16 | - PRIVATE_KEY_FILE_NAME: "github_deploy_key.enc" 17 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## dateStyle and timeStyle option on Intl.DateTimeFormat API Specification [draft] 2 | 3 | This proposal adds two options to `Intl.DateTimeFormat`: `dateStyle` and `timeStyle`. These options give a compact way to request the appropriate, locale-specific way to ask for a date and time of given lengths. 4 | 5 | ### Status 6 | 7 | Current Stage: 8 | 9 | * __Stage 4__ 10 | 11 | Spec Text: 12 | 13 | * https://tc39.github.io/proposal-intl-datetime-style/ 14 | 15 | ### Authors 16 | 17 | * Zibi Braniecki (@zbraniecki) 18 | 19 | ### Reviewers 20 | 21 | * Frank Tang (@FrankYFTang) 22 | * Nathan Hammond (@nathanhammond) 23 | 24 | ### Informative 25 | 26 | This proposal is based on the CLDR Date/Time Patterns: 27 | 28 | * http://cldr.unicode.org/translation/date-time-patterns#TOC-Basic-Time-Formats 29 | * http://cldr.unicode.org/translation/date-time-patterns#TOC-Basic-Date-Formats 30 | * http://unicode.org/reports/tr35/tr35-dates.html 31 | 32 | ### Usage 33 | 34 | ```javascript 35 | let o = new Intl.DateTimeFormat("en" , { 36 | timeStyle: "short" 37 | }); 38 | console.log(o.format(Date.now())); // "13:31" 39 | 40 | let o = new Intl.DateTimeFormat("en" , { 41 | dateStyle: "short" 42 | }); 43 | console.log(o.format(Date.now())); // "21.03.2012" 44 | 45 | let o = new Intl.DateTimeFormat("en" , { 46 | timeStyle: "medium", 47 | dateStyle: "short" 48 | }); 49 | console.log(o.format(Date.now())); // "21.03.2012, 13:31" 50 | ``` 51 | 52 | 53 | ### Render Spec 54 | 55 | ```bash 56 | npm install 57 | npm run build 58 | open index.html 59 | ``` 60 | 61 | ### Backpointers 62 | 63 | * https://github.com/tc39/ecma402/issues/108 64 | -------------------------------------------------------------------------------- /biblio.json: -------------------------------------------------------------------------------- 1 | { 2 | "https://tc39.github.io/ecma402/": [ 3 | { 4 | "type": "clause", 5 | "title": "Internal slots of Service Constructors", 6 | "number": "9.1", 7 | "id": "sec-internal-slots" 8 | }, 9 | { 10 | "type": "op", 11 | "aoid": "BasicFormatMatcher", 12 | "id": "sec-basicformatmatcher" 13 | }, 14 | { 15 | "type": "op", 16 | "aoid": "BestFitFormatMatcher", 17 | "id": "sec-bestfitformatmatcher" 18 | }, 19 | { 20 | "type": "op", 21 | "aoid": "CanonicalizeLocaleList", 22 | "id": "sec-canonicalizelocalelist" 23 | }, 24 | { 25 | "type": "op", 26 | "aoid": "CanonicalizeTimeZoneName", 27 | "id": "sec-canonicalizetimezonename" 28 | }, 29 | { 30 | "type": "op", 31 | "aoid": "DefaultTimeZone", 32 | "id": "sec-defaulttimezone" 33 | }, 34 | { 35 | "type": "op", 36 | "aoid": "IsValidTimeZoneName", 37 | "id": "sec-isvalidtimezonename" 38 | }, 39 | { 40 | "type": "op", 41 | "aoid": "GetOption", 42 | "id": "sec-getoption" 43 | }, 44 | { 45 | "type": "op", 46 | "aoid": "ResolveLocale", 47 | "id": "sec-resolvelocale" 48 | }, 49 | { 50 | "type": "op", 51 | "aoid": "SupportedLocales", 52 | "id": "sec-supportedlocales" 53 | }, 54 | { 55 | "type": "op", 56 | "aoid": "UnwrapDateTimeFormat", 57 | "id": "sec-unwrapdatetimeformat" 58 | } 59 | ] 60 | } 61 | -------------------------------------------------------------------------------- /deploy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -ev 4 | 5 | # Pull requests and commits to other branches shouldn't try to deploy, just build to verify 6 | if [[ "$TRAVIS_BRANCH" != master || "$TRAVIS_PULL_REQUEST" != false ]]; then 7 | echo "Skipping deploy; just doing a build." 8 | npm run build 9 | exit 0 10 | fi 11 | 12 | # Enable SSH authentication 13 | 14 | ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key" 15 | ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv" 16 | ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR} 17 | ENCRYPTED_IV=${!ENCRYPTED_IV_VAR} 18 | 19 | $(npm bin)/set-up-ssh --key "$ENCRYPTED_KEY" \ 20 | --iv "$ENCRYPTED_IV" \ 21 | --path-encrypted-key "$PRIVATE_KEY_FILE_NAME" 22 | 23 | # Update the content from the `gh-pages` branch 24 | 25 | $(npm bin)/update-branch --commands "npm run build" \ 26 | --commit-message "Update gh-pages [skip ci]" \ 27 | --directory "out" \ 28 | --distribution-branch "gh-pages" \ 29 | --source-branch "master" 30 | -------------------------------------------------------------------------------- /github_deploy_key.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tc39/proposal-intl-datetime-style/f3513e337931163340e185da2f74d889b89678d9/github_deploy_key.enc -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "private": true, 3 | "name": "proposal-ecma402-datetime-style", 4 | "version": "0.1.0", 5 | "description": "ECMAScript date/time style proposal", 6 | "repository": "tc39/proposal-ecma402-datetime-style", 7 | "author": "Ecma TC39", 8 | "license": "SEE LICENSE IN https://tc39.github.io/ecma262/#sec-copyright-and-software-license", 9 | "homepage": "https://tc39.github.io/proposal-ecma402-datetime-style/", 10 | "scripts": { 11 | "build": "[ -d out ] || mkdir out && ecmarkup spec.html out/index.html" 12 | }, 13 | "dependencies": { 14 | "ecmarkup": "^3.19.0" 15 | }, 16 | "devDependencies": { 17 | "@alrra/travis-scripts": "^3.0.0" 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /spec.html: -------------------------------------------------------------------------------- 1 |
  2 | title: dateStyle and timeStyle options for DateTimeFormat
  3 | status: proposal
  4 | stage: 3
  5 | location: https://tc39.github.io/proposal-ecma402-datetime-style/
  6 | copyright: false
  7 | contributors: Zibi Braniecki, Daniel Ehrenberg
  8 | 
9 | 10 | 11 | 12 | 13 |

Introduction

14 | 15 |

This proposal adds two options to `Intl.DateTimeFormat`: `dateStyle` and `timeStyle`. These options give a compact way to request the appropriate, locale-specific way to ask for a date and time of given lengths. See the README for more context.

16 |
17 | 18 | 19 |

DateTimeFormat Objects

20 | 21 | 22 |

Abstract Operations For DateTimeFormat Objects

23 | 24 |

25 | 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: 26 |

27 | 28 | 29 | Components of date and time formats 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 |
Internal SlotPropertyValues
[[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"`
84 |
85 | 86 | 87 |

InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )

88 | 89 |

90 | The abstract operation InitializeDateTimeFormat accepts the arguments _dateTimeFormat_ (which must be an object), _locales_, and _options_. It initializes _dateTimeFormat_ as a DateTimeFormat object. This abstract operation functions as follows: 91 |

92 | 93 | 94 | 1. Let _requestedLocales_ be ? CanonicalizeLocaleList(_locales_). 95 | 1. Let _options_ be ? ToDateTimeOptions(_options_, `"any"`, `"date"`). 96 | 1. Let _opt_ be a new Record. 97 | 1. Let _matcher_ be ? GetOption(_options_, `"localeMatcher"`, `"string"`, « `"lookup"`, `"best fit"` », `"best fit"`). 98 | 1. Set _opt_.[[localeMatcher]] to _matcher_. 99 | 1. Let _hour12_ be ? GetOption(_options_, `"hour12"`, `"boolean"`, *undefined*, *undefined*). 100 | 1. Let _hourCycle_ be ? GetOption(_options_, `"hourCycle"`, `"string"`, « `"h11"`, `"h12"`, `"h23"`, `"h24"` », *undefined*). 101 | 1. If _hour12_ is not *undefined*, then 102 | 1. Let _hourCycle_ be *null*. 103 | 1. Set _opt_.[[hc]] to _hourCycle_. 104 | 1. Let _localeData_ be %DateTimeFormat%.[[LocaleData]]. 105 | 1. Let _r_ be ResolveLocale( %DateTimeFormat%.[[AvailableLocales]], _requestedLocales_, _opt_, %DateTimeFormat%.[[RelevantExtensionKeys]], _localeData_). 106 | 1. Set _dateTimeFormat_.[[Locale]] to _r_.[[locale]]. 107 | 1. Set _dateTimeFormat_.[[Calendar]] to _r_.[[ca]]. 108 | 1. Set _dateTimeFormat_.[[HourCycle]] to _r_.[[hc]]. 109 | 1. Set _dateTimeFormat_.[[NumberingSystem]] to _r_.[[nu]]. 110 | 1. Let _dataLocale_ be _r_.[[dataLocale]]. 111 | 1. Let _timeZone_ be ? Get(_options_, `"timeZone"`). 112 | 1. If _timeZone_ is not *undefined*, then 113 | 1. Let _timeZone_ be ? ToString(_timeZone_). 114 | 1. If the result of IsValidTimeZoneName(_timeZone_) is *false*, then 115 | 1. Throw a *RangeError* exception. 116 | 1. Let _timeZone_ be CanonicalizeTimeZoneName(_timeZone_). 117 | 1. Else, 118 | 1. Let _timeZone_ be DefaultTimeZone(). 119 | 1. Set _dateTimeFormat_.[[TimeZone]] to _timeZone_. 120 | 1. Let _opt_ be a new Record. 121 | 1. For each row of , except the header row, do 122 | 1. Let _prop_ be the name given in the Property column of the row. 123 | 1. Let _value_ be ? GetOption(_options_, _prop_, `"string"`, « the strings given in the Values column of the row », *undefined*). 124 | 1. Set _opt_.[[<_prop_>]] to _value_. 125 | 1. Let _matcher_ be ? GetOption(_options_, `"formatMatcher"`, `"string"`, « `"basic"`, `"best fit"` », `"best fit"`). 126 | 1. Let _dataLocaleData_ be _localeData_.[[<_dataLocale_>]]. 127 | 1. Let _formats_ be _dataLocaleData_.[[formats]]. 128 | 1. Let _dateStyle_ be ? GetOption(_options_, `"dateStyle"`, `"string"`, « `"full"`, `"long"`, `"medium"`, `"short"` », *undefined*). 129 | 1. Set _dateTimeFormat_.[[DateStyle]] to _dateStyle_. 130 | 1. Let _timeStyle_ be ? GetOption(_options_, `"timeStyle"`, `"string"`, « `"full"`, `"long"`, `"medium"`, `"short"` », *undefined*). 131 | 1. Set _dateTimeFormat_.[[TimeStyle]] to _timeStyle_. 132 | 1. If _dateStyle_ is *undefined* and _timeStyle_ is *undefined*, then 133 | 1. Let _formats_ be _dataLocaleData_.[[formats]]. 134 | 1. If _matcher_ is `"basic"`, then 135 | 1. Let _bestFormat_ be BasicFormatMatcher(_opt_, _formats_). 136 | 1. Else, 137 | 1. Let _bestFormat_ be BestFitFormatMatcher(_opt_, _formats_). 138 | 1. Else, 139 | 1. For each row in , except the header row, do 140 | 1. Let _prop_ be the name given in the Property column of the row. 141 | 1. Let _p_ be _opt_.[[<_prop_>]]. 142 | 1. If _p_ is not *undefined*, then 143 | 1. Throw a *TypeError* exception. 144 | 1. Let _bestFormat_ be DateTimeStyleFormat(_dateStyle_, _timeStyle_, _dataLocaleData_). 145 | 1. For each row in , except the header row, do 146 | 1. Let _prop_ be the name given in the Property column of the row. 147 | 1. Let _p_ be _bestFormat_.[[<_prop_>]]. 148 | 1. If _p_ not *undefined*, then 149 | 1. Set _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the row to _p_. 150 | 1. If _dateTimeFormat_.[[Hour]] is not *undefined*, then 151 | 1. Let _hcDefault_ be _dataLocaleData_.[[hourCycle]]. 152 | 1. Let _hc_ be _dateTimeFormat_.[[HourCycle]]. 153 | 1. If _hc_ is *null*, then 154 | 1. Set _hc_ to _hcDefault_. 155 | 1. If _hour12_ is not *undefined*, then 156 | 1. If _hour12_ is *true*, then 157 | 1. If _hcDefault_ is `"h11"` or `"h23"`, then 158 | 1. Set _hc_ to `"h11"`. 159 | 1. Else, 160 | 1. Set _hc_ to `"h12"`. 161 | 1. Else, 162 | 1. Assert: _hour12_ is *false*. 163 | 1. If _hcDefault_ is `"h11"` or `"h23"`, then 164 | 1. Set _hc_ to `"h23"`. 165 | 1. Else, 166 | 1. Set _hc_ to `"h24"`. 167 | 1. Set _dateTimeFormat_.[[HourCycle]] to _hc_. 168 | 1. If _dateTimeformat_.[[HourCycle]] is `"h11"` or `"h12"`, then 169 | 1. Let _pattern_ be _bestFormat_.[[pattern12]]. 170 | 1. Else, 171 | 1. Let _pattern_ be _bestFormat_.[[pattern]]. 172 | 1. Else, 173 | 1. Set _dateTimeFormat_.[[HourCycle]] to *undefined*. 174 | 1. Let _pattern_ be _bestFormat_.[[pattern]]. 175 | 1. Set _dateTimeFormat_.[[Pattern]] to _pattern_. 176 | 1. Return _dateTimeFormat_. 177 | 178 |
179 | 180 | 181 |

ToDateTimeOptions ( _options_, _required_, _defaults_ )

182 | 183 |

184 | When the ToDateTimeOptions abstract operation is called with arguments _options_, _required_, and _defaults_, the following steps are taken: 185 |

186 | 187 | 188 | 1. If _options_ is *undefined*, let _options_ be *null*; otherwise let _options_ be ? ToObject(_options_). 189 | 1. Let _options_ be ObjectCreate(_options_). 190 | 1. Let _needDefaults_ be *true*. 191 | 1. If _required_ is *"date"* or *"any"*, then 192 | 1. For each of the property names *"weekday"*, *"year"*, *"month"*, *"day"*, do 193 | 1. Let _prop_ be the property name. 194 | 1. Let _value_ be ? Get(_options_, _prop_). 195 | 1. If _value_ is not *undefined*, let _needDefaults_ be *false*. 196 | 1. If _required_ is *"time"* or *"any"*, then 197 | 1. For each of the property names *"hour"*, *"minute"*, *"second"*, do 198 | 1. Let _prop_ be the property name. 199 | 1. Let _value_ be ? Get(_options_, _prop_). 200 | 1. If _value_ is not *undefined*, let _needDefaults_ be *false*. 201 | 1. Let _dateStyle_ be ? Get(_options_, *"dateStyle"*). 202 | 1. Let _timeStyle_ be ? Get(_options_, *"timeStyle"*). 203 | 1. If _dateStyle_ is not *undefined* or _timeStyle_ is not *undefined*, let _needDefaults_ be *false*. 204 | 1. If _required_ is *"date"* and _timeStyle_ is not *undefined*, 205 | 1. Throw a *TypeError* exception. 206 | 1. If _required_ is *"time"* and _dateStyle_ is not *undefined*, 207 | 1. Throw a *TypeError* exception. 208 | 1. If _needDefaults_ is *true* and _defaults_ is either *"date"* or *"all"*, then 209 | 1. For each of the property names *"year"*, *"month"*, *"day"*, do 210 | 1. Perform ? CreateDataPropertyOrThrow(_options_, _prop_, *"numeric"*). 211 | 1. If _needDefaults_ is *true* and _defaults_ is either *"time"* or *"all"*, then 212 | 1. For each of the property names *"hour"*, *"minute"*, *"second"*, do 213 | 1. Perform ? CreateDataPropertyOrThrow(_options_, _prop_, *"numeric"*). 214 | 1. Return _options_. 215 | 216 |
217 | 218 | 219 |

DateTimeStyleFormat ( _dateStyle_, _timeStyle_, _dataLocaleData_ )

220 |

The DateTimeStyleFormat abstract operation accepts arguments _dateStyle_ and _timeStyle_, which are each either *undefined*, `"full"`, `"long"`, `"medium"`, or `"short"`, at least one of which is not *undefined*, and _dataLocaleData_, which is a record from %DateTimeFormat%.[[LocaleData]][_locale_] for some locale _locale_. It returns the appropriate format record for date time formatting based on the parameters.

221 | 222 | 1. If _timeStyle_ is not *undefined*, then 223 | 1. Assert: _timeStyle_ is one of `"full"`, `"long"`, `"medium"`, or `"short"`. 224 | 1. Let _timeFormat_ be _dataLocaleData_.[[TimeFormat]].[[<_timeStyle_>]]. 225 | 1. If _dateStyle_ is not *undefined*, then 226 | 1. Assert: _dateStyle_ is one of `"full"`, `"long"`, `"medium"`, or `"short"`. 227 | 1. Let _dateFormat_ be _dataLocaleData_.[[DateFormat]].[[<_dateStyle_>]]. 228 | 1. If _dateStyle_ is not *undefined* and _timeStyle_ is not *undefined*, then 229 | 1. Let _format_ be a new Record. 230 | 1. Add to _format_ all fields from _dateFormat_ except [[pattern]]. 231 | 1. Add to _format_ all fields from _timeFormat_ except [[pattern]] and [[pattern12]], if present. 232 | 1. Let _connector_ be _dataLocaleData_.[[DateTimeFormat]].[[<_dateStyle_>]]. 233 | 1. Let _pattern_ be the string _connector_ with the substring `"{0}"` replaced with _timeFormat_.[[pattern]] and the substring `"{1}"` replaced with _dateFormat_.[[pattern]]. 234 | 1. Set _format_.[[pattern]] to _pattern_. 235 | 1. If _timeFormat_ has a [[pattern12]] field, then 236 | 1. Let _pattern12_ be the string _connector_ with the substring `"{0}"` replaced with _timeFormat_.[[pattern12]] and the substring `"{1}"` replaced with _dateFormat_.[[pattern]]. 237 | 1. Set _format_.[[pattern12]] to _pattern12_. 238 | 1. Return _format_. 239 | 1. If _timeStyle_ is not *undefined*, then 240 | 1. Return _timeFormat_. 241 | 1. Assert: _dateStyle_ is not *undefined*. 242 | 1. Return _dateFormat_. 243 | 244 |
245 |
246 | 247 | 248 |

The Intl.DateTimeFormat Constructor

249 | 250 |

251 | The Intl.DateTimeFormat constructor is the %DateTimeFormat% intrinsic object and a standard built-in property of the Intl object. Behaviour common to all service constructor properties of the Intl object is specified in . 252 |

253 | 254 | 255 |

Intl.DateTimeFormat ( [ _locales_ [ , _options_ ] ] )

256 | 257 |

258 | When the `Intl.DateTimeFormat` function is called with optional arguments _locales_ and _options_, the following steps are taken: 259 |

260 | 261 | 262 | 1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget. 263 | 1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, `"%DateTimeFormatPrototype%"`, « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], [[DateStyle]], [[TimeStyle]], [[Pattern]], [[BoundFormat]] »). 264 | 1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_). 265 | 266 | 267 | 268 | 4. Let _this_ be the *this* value. 269 | 1. If NewTarget is *undefined* and ? InstanceofOperator(_this_, %DateTimeFormat%), then 270 | 1. Perform ? DefinePropertyOrThrow(_this_, Intl.[[FallbackSymbol]], { [[Value]]: _dateTimeFormat_, [[Writable]]: *false*, [[Enumerable]]: *false*, [[Configurable]]: *false* }). 271 | 1. Return _this_. 272 | 273 | 274 | 275 | 6. Return _dateTimeFormat_. 276 | 277 |
278 |
279 | 280 | 281 |

Properties of the Intl.DateTimeFormat Constructor

282 | 283 | 284 |

Internal slots

285 | 286 |

287 | The value of the [[AvailableLocales]] internal slot is implementation defined within the constraints described in . 288 |

289 | 290 |

291 | The value of the [[RelevantExtensionKeys]] internal slot is « `"ca"`, `"nu"`, `"hc"` ». 292 |

293 | 294 | 295 | Unicode Technical Standard 35 describes three locale extension keys that are relevant to date and time formatting, `"ca"` for calendar, `"tz"` for time zone, `"hc"` for hour cycle, and implicitly `"nu"` for the numbering system of the number format used for numbers within the date format. DateTimeFormat, however, requires that the time zone is specified through the timeZone property in the options objects. 296 | 297 | 298 |

299 | The value of the [[LocaleData]] internal slot is implementation defined within the constraints described in and the following additional constraints: 300 |

301 | 302 |
    303 |
  • 304 | The list that is the value of the `"nu"` field of any locale field of [[LocaleData]] must not include the values `"native"`, `"traditio"`, or `"finance"`. 305 |
  • 306 |
  • 307 | [[LocaleData]][locale].hc must be « *null*, `"h11"`, `"h12"`, `"h23"`, `"h24"` » for all locale values. 308 |
  • 309 |
  • 310 | [[LocaleData]][locale] must have a hourCycle field with a String value equal to `"h11"`, `"h12"`, `"h23"`, or `"h24"` for all locale values. 311 |
  • 312 |
  • 313 | [[LocaleData]][locale] must have a formats field for all locale values. The value of this field must be a list of records, each of which has a subset of the fields shown in , where each field must have one of the values specified for the field in . Multiple records in a list may use the same subset of the fields as long as they have different values for the fields. The following subsets must be available for each locale: 314 |
      315 |
    • weekday, year, month, day, hour, minute, second
    • 316 |
    • weekday, year, month, day
    • 317 |
    • year, month, day
    • 318 |
    • year, month
    • 319 |
    • month, day
    • 320 |
    • hour, minute, second
    • 321 |
    • hour, minute
    • 322 |
    323 | Each of the records must also have a pattern field, whose value is a String value that contains for each of the date and time format component fields of the record a substring starting with `"{"`, followed by the name of the field, followed by `"}"`. If the record has an hour field, it must also have a pattern12 field, whose value is a String value that, in addition to the substrings of the pattern field, contains a substring `"{ampm}"`. 324 |
  • 325 |
  • 326 | 327 | [[LocaleData]][locale] must contain [[DateFormat]], [[TimeFormat]] and [[DateTimeFormat]] fields, the value of these fields are Records, where each of which has [[full]], [[long]], [[medium]] and [[short]] fields. For [[DateFormat]] and [[TimeFormat]], the value of these fields must be a record, which has a subset of the fields shown in Table 1, where each field must have one of the values specified for the field in Table 1. Each of the records must also have a pattern field, whose value is a String value that contains for each of the date and time format component fields of the record a substring starting with `"{"`, followed by the name of the field, followed by `"}"`. If the record has an hour field, it must also have a pattern12 field, whose value is a String value that, in addition to the substrings of the pattern field, contains a substring `"{ampm}"`. For [[DateTimeFormat]], the field value must be a string pattern which contains the strings `"{0}"` and `"{1}"`. 328 | 329 |
  • 330 |
331 | 332 |

333 | EXAMPLE An implementation might include the following record as part of its English locale data: {[[Hour]]: `"numeric"`, [[Minute]]: `"2-digit"`, [[Second]]: `"2-digit"`, [[Pattern]]: `"{hour}:{minute}:{second}"`, [[Pattern12]]: `"{hour}:{minute}:{second} {ampm}"`}. 334 |

335 | 336 | 337 | It is recommended that implementations use the locale data provided by the Common Locale Data Repository (available at http://cldr.unicode.org/). 338 | 339 |
340 |
341 | 342 | 343 |

Properties of the Intl.DateTimeFormat Prototype Object

344 | 345 | 346 |

Intl.DateTimeFormat.prototype.resolvedOptions ()

347 | 348 |

349 | This function provides access to the locale and formatting options computed during initialization of the object. 350 |

351 | 352 | 353 | 1. Let _dtf_ be *this* value. 354 | 1. If Type(_dtf_) is not Object, throw a *TypeError* exception. 355 | 1. Let _dtf_ be ? UnwrapDateTimeFormat(_dtf_). 356 | 1. Let _options_ be ! ObjectCreate(%ObjectPrototype%). 357 | 1. For each row of , except the header row, in table order, do 358 | 1. Let _p_ be the Property value of the current row. 359 | 1. If _p_ is `"hour12"`, then 360 | 1. Let _hc_ be _dtf_.[[HourCycle]]. 361 | 1. If _hc_ is `"h11"` or `"h12"`, let _v_ be *true*. 362 | 1. Else if, _hc_ is `"h23"` or `"h24"`, let _v_ be *false*. 363 | 1. Else, let _v_ be *undefined*. 364 | 1. Else, 365 | 1. Let _v_ be the value of _dtf_'s internal slot whose name is the Internal Slot value of the current row. 366 | 1. If the Internal Slot value of the current row is an Internal Slot value in , then 367 | 1. If _dtf_.[[DateStyle]] is not *undefined* or _dtf_.[[TimeStyle]] is not *undefined*, then 368 | 1. Let _v_ be *undefined*. 369 | 1. If _v_ is not *undefined*, then 370 | 1. Perform ! CreateDataPropertyOrThrow(_options_, _p_, _v_). 371 | 1. Return _options_. 372 | 373 | 374 | 375 | Resolved Options of DateTimeFormat Instances 376 | 377 | 378 | 379 | 380 | 381 | 382 | 383 | 384 | 385 | 386 | 387 | 388 | 389 | 390 | 391 | 392 | 393 | 394 | 395 | 396 | 397 | 398 | 399 | 400 | 401 | 402 | 403 | 404 | 405 | 406 | 407 | 408 | 409 | 410 | 411 | 412 | 413 | 414 | 415 | 416 | 417 | 418 | 419 | 420 | 421 | 422 | 423 | 424 | 425 | 426 | 427 | 428 | 429 | 430 | 431 | 432 | 433 | 434 | 435 | 436 | 437 | 438 | 439 | 440 | 441 | 442 | 443 | 444 | 445 | 446 | 447 | 448 | 449 | 450 | 451 |
Internal SlotProperty
[[Locale]]`"locale"`
[[Calendar]]`"calendar"`
[[NumberingSystem]]`"numberingSystem"`
[[TimeZone]]`"timeZone"`
[[HourCycle]]`"hourCycle"`
`"hour12"`
[[Weekday]]`"weekday"`
[[Era]]`"era"`
[[Year]]`"year"`
[[Month]]`"month"`
[[Day]]`"day"`
[[Hour]]`"hour"`
[[Minute]]`"minute"`
[[Second]]`"second"`
[[TimeZoneName]]`"timeZoneName"`
[[DateStyle]]`"dateStyle"`
[[TimeStyle]]`"timeStyle"`
452 |
453 | 454 |

455 | For web compatibility reasons, if the property hourCycle is set, the hour12 property should be set to *true* when hourCycle is `"h11"` or `"h12"`, or to *false* when hourCycle is `"h23"` or `"h24"`. 456 |

457 | 458 | 459 | In this version of the ECMAScript 2020 Internationalization API, the timeZone property will be the name of the default time zone if no timeZone property was provided in the options object provided to the Intl.DateTimeFormat constructor. The first edition left the timeZone property *undefined* in this case. 460 | 461 | 462 | 463 | For compatibility with versions prior to the fifth edition, the `"hour12"` property is set in addition to the `"hourCycle"` property. 464 | 465 |
466 | 467 |
468 | 469 | 470 |

Properties of Intl.DateTimeFormat Instances

471 | 472 |

473 | Intl.DateTimeFormat instances inherit properties from %DateTimeFormatPrototype%. 474 |

475 | 476 |

477 | Intl.DateTimeFormat instances have an [[InitializedDateTimeFormat]] internal slot. 478 |

479 | 480 |

481 | Intl.DateTimeFormat instances also have several internal slots that are computed by the constructor: 482 |

483 | 484 | 494 |
495 |
496 | --------------------------------------------------------------------------------