-
Notifications
You must be signed in to change notification settings - Fork 116
Normative: Add fractionalSecondDigits option #347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,6 +58,11 @@ <h1>Abstract Operations For DateTimeFormat Objects</h1> | |
| <td>*"second"*</td> | ||
| <td>*"2-digit"*, *"numeric"*</td> | ||
| </tr> | ||
| <tr> | ||
| <td>[[FractionalSecondDigits]]</td> | ||
| <td>*"fractionalSecondDigits"*</td> | ||
| <td>*1*, *2*, *3*</td> | ||
| </tr> | ||
| <tr> | ||
| <td>[[TimeZoneName]]</td> | ||
| <td>*"timeZoneName"*</td> | ||
|
|
@@ -116,7 +121,10 @@ <h1>InitializeDateTimeFormat ( _dateTimeFormat_, _locales_, _options_ )</h1> | |
| 1. Let _opt_ be a new Record. | ||
| 1. For each row of <emu-xref href="#table-datetimeformat-components"></emu-xref>, except the header row, in table order, do | ||
| 1. Let _prop_ be the name given in the Property column of the row. | ||
| 1. Let _value_ be ? GetOption(_options_, _prop_, *"string"*, « the strings given in the Values column of the row », *undefined*). | ||
| 1. If _prop_ is *"fractionalSecondDigits"*, then | ||
| 1. Let _value_ be ? GetNumberOption(options, *"fractionalSecondDigits"*, 1, 3, *undefined*). | ||
| 1. Else, | ||
| 1. Let _value_ be ? GetOption(_options_, _prop_, *"string"*, « the strings given in the Values column of the row », *undefined*). | ||
| 1. Set _opt_.[[<_prop_>]] to _value_. | ||
| 1. Let _dataLocaleData_ be _localeData_.[[<_dataLocale_>]]. | ||
| 1. Let _matcher_ be ? GetOption(_options_, *"formatMatcher"*, *"string"*, « *"basic"*, *"best fit"* », *"best fit"*). | ||
|
|
@@ -189,7 +197,7 @@ <h1>ToDateTimeOptions ( _options_, _required_, _defaults_ )</h1> | |
| 1. Let _value_ be ? Get(_options_, _prop_). | ||
| 1. If _value_ is not *undefined*, let _needDefaults_ be *false*. | ||
| 1. If _required_ is *"time"* or *"any"*, then | ||
| 1. For each of the property names *"hour"*, *"minute"*, *"second"*, do | ||
| 1. For each of the property names *"hour"*, *"minute"*, *"second"*, *"fractionalSecondDigits"*, do | ||
| 1. Let _prop_ be the property name. | ||
| 1. Let _value_ be ? Get(_options_, _prop_). | ||
| 1. If _value_ is not *undefined*, let _needDefaults_ be *false*. | ||
|
|
@@ -263,7 +271,10 @@ <h1>BasicFormatMatcher ( _options_, _formats_ )</h1> | |
| 1. If _optionsProp_ is *undefined* and _formatProp_ is not *undefined*, then decrease _score_ by _additionPenalty_. | ||
| 1. Else if _optionsProp_ is not *undefined* and _formatProp_ is *undefined*, then decrease _score_ by _removalPenalty_. | ||
| 1. Else if _optionsProp_ ≠ _formatProp_, then | ||
| 1. Let _values_ be « *"2-digit"*, *"numeric"*, *"narrow"*, *"short"*, *"long"* ». | ||
| 1. If _property_ is *"fractionalSecondDigits"*, then | ||
| 1. Let _values_ be « *1*, *2*, *3* ». | ||
| 1. Else, | ||
| 1. Let _values_ be « *"2-digit"*, *"numeric"*, *"narrow"*, *"short"*, *"long"* ». | ||
| 1. Let _optionsPropIndex_ be the index of _optionsProp_ within _values_. | ||
| 1. Let _formatPropIndex_ be the index of _formatProp_ within _values_. | ||
| 1. Let _delta_ be max(min(_formatPropIndex_ - _optionsPropIndex_, 2), -2). | ||
|
|
@@ -325,15 +336,25 @@ <h1>PartitionDateTimePattern ( _dateTimeFormat_, _x_ )</h1> | |
| 1. Perform ! CreateDataPropertyOrThrow(_nf2Options_, *"minimumIntegerDigits"*, 2). | ||
| 1. Perform ! CreateDataPropertyOrThrow(_nf2Options_, *"useGrouping"*, *false*). | ||
| 1. Let _nf2_ be ? Construct(%NumberFormat%, « _locale_, _nf2Options_ »). | ||
| 1. Let _fractionalSecondDigits_ be _dateTimeFormat_.[[FractionalSecondDigits]]. | ||
| 1. If _fractionalSecondDigits_ is not *undefined*, then | ||
| 1. Let _nf3Options_ be ObjectCreate(*null*). | ||
| 1. Perform ! CreateDataPropertyOrThrow(_nf3Options_, *"minimumIntegerDigits"*, _fractionalSecondDigits_). | ||
| 1. Perform ! CreateDataPropertyOrThrow(_nf3Options_, *"useGrouping"*, *false*). | ||
| 1. Let _nf3_ be ? Construct(%NumberFormat%, « _locale_, _nf3Options_ »). | ||
| 1. Let _tm_ be ToLocalTime(_x_, _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]). | ||
| 1. Let _result_ be a new empty List. | ||
| 1. Let _patternParts_ be PartitionPattern(_dateTimeFormat_.[[Pattern]]). | ||
| 1. For each element _patternPart_ of _patternParts_, in List order, do | ||
| 1. Let _p_ be _patternPart_.[[Type]]. | ||
| 1. If _p_ is *"literal"*, then | ||
| 1. Append a new Record { [[Type]]: *"literal"*, [[Value]]: _patternPart_.[[Value]] } as the last element of the list _result_. | ||
| 1. Else if _p_ is equal to *"fractionalSecondDigits"*, then | ||
| 1. Let _v_ be _tm_.[[Millisecond]]. | ||
| 1. Let _v_ be floor(_v_ × 10<sup>( _fractionalSecondDigits_ - 3 )</sup>). | ||
| 1. Let _fv_ be FormatNumeric(_nf3_, _v_). | ||
| 1. Append a new Record { [[Type]]: *"fractionalSecond"*, [[Value]]: _fv_ } as the last element of _result_. | ||
| 1. Else if _p_ matches a Property column of the row in <emu-xref href="#table-datetimeformat-components"></emu-xref>, then | ||
| 1. Let _f_ be the value of _dateTimeFormat_'s internal slot whose name is the Internal Slot column of the matching row. | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The removal of this line (line 336) is a mistake during editing. Please add it back @leobalter Totally my fault. |
||
| 1. Let _v_ be the value of _tm_'s field whose name is the Internal Slot column of the matching row. | ||
| 1. If _p_ is *"year"* and _v_ ≤ 0, let _v_ be 1 - _v_. | ||
| 1. If _p_ is *"month"*, increase _v_ by 1. | ||
|
|
@@ -481,6 +502,10 @@ <h1>ToLocalTime ( _t_, _calendar_, _timeZone_ )</h1> | |
| <td>[[Second]]</td> | ||
| <td>`SecFromTime(tz)` specified in ES2021's <emu-xref href="#sec-hours-minutes-second-and-milliseconds">Hours, Minutes, Second, and Milliseconds</emu-xref></td> | ||
| </tr> | ||
| <tr> | ||
| <td>[[Millisecond]]</td> | ||
| <td>`msFromTime(tz)` specified in ES2021's <emu-xref href="#sec-hours-minutes-second-and-milliseconds">Hours, Minutes, Second, and Milliseconds</emu-xref></td> | ||
| </tr> | ||
| <tr> | ||
| <td>[[InDST]]</td> | ||
| <td>Calculate *true* or *false* using the best available information about the specified _calendar_ and _timeZone_, including current and historical information about time zone offsets from UTC and daylight saving time rules.</td> | ||
|
|
@@ -535,7 +560,7 @@ <h1>Intl.DateTimeFormat ( [ _locales_ [ , _options_ ] ] )</h1> | |
|
|
||
| <emu-alg> | ||
| 1. If NewTarget is *undefined*, let _newTarget_ be the active function object, else let _newTarget_ be NewTarget. | ||
| 1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%DateTimeFormat.prototype%"*, « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] »). | ||
| 1. Let _dateTimeFormat_ be ? OrdinaryCreateFromConstructor(_newTarget_, *"%DateTimeFormat.prototype%"*, « [[InitializedDateTimeFormat]], [[Locale]], [[Calendar]], [[NumberingSystem]], [[TimeZone]], [[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[FractionalSecondDigits]], [[TimeZoneName]], [[HourCycle]], [[Pattern]], [[BoundFormat]] »). | ||
| 1. Perform ? InitializeDateTimeFormat(_dateTimeFormat_, _locales_, _options_). | ||
| </emu-alg> | ||
| <emu-normative-optional> | ||
|
|
@@ -623,11 +648,13 @@ <h1>Internal slots</h1> | |
| <li> | ||
| [[LocaleData]].[[<_locale_>]] must have a [[formats]] field. This formats field must have a [[<_calendar_>]] field for all calendar values _calendar_. The value of this field must be a list of records, each of which has a subset of the fields shown in <emu-xref href="#table-datetimeformat-components"></emu-xref>, where each field must have one of the values specified for the field in <emu-xref href="#table-datetimeformat-components"></emu-xref>. 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: | ||
| <ul> | ||
| <li>weekday, year, month, day, hour, minute, second, fractionalSecondDigits</li> | ||
| <li>weekday, year, month, day, hour, minute, second</li> | ||
| <li>weekday, year, month, day</li> | ||
| <li>year, month, day</li> | ||
| <li>year, month</li> | ||
| <li>month, day</li> | ||
| <li>hour, minute, second, fractionalSecondDigits</li> | ||
| <li>hour, minute, second</li> | ||
| <li>hour, minute</li> | ||
| </ul> | ||
|
|
@@ -811,6 +838,10 @@ <h1>Intl.DateTimeFormat.prototype.resolvedOptions ( )</h1> | |
| <td>[[Second]]</td> | ||
| <td>*"second"*</td> | ||
| </tr> | ||
| <tr> | ||
| <td>[[FractionalSecondDigits]]</td> | ||
| <td>*"fractionalSecondDigits"*</td> | ||
| </tr> | ||
| <tr> | ||
|
FrankYFTang marked this conversation as resolved.
|
||
| <td>[[TimeZoneName]]</td> | ||
| <td>*"timeZoneName"*</td> | ||
|
|
@@ -861,6 +892,7 @@ <h1>Properties of Intl.DateTimeFormat Instances</h1> | |
| <li>[[NumberingSystem]] is a String value with the *"type"* given in Unicode Technical Standard 35 for the numbering system used for formatting.</li> | ||
| <li>[[TimeZone]] is a String value with the IANA time zone name of the time zone used for formatting.</li> | ||
| <li>[[Weekday]], [[Era]], [[Year]], [[Month]], [[Day]], [[Hour]], [[Minute]], [[Second]], [[TimeZoneName]] are each either *undefined*, indicating that the component is not used for formatting, or one of the String values given in <emu-xref href="#table-datetimeformat-components"></emu-xref>, indicating how the component should be presented in the formatted output.</li> | ||
| <li>[[FractionalSecondDigits]] is either *undefined* or a positive, non-negative integer Number value indicating the fraction digits to be used for fractional seconds. Numbers will be rounded or padded with trailing zeroes if necessary. </li> | ||
| <li>[[HourCycle]] is a String value indicating whether the 12-hour format (*"h11"*, *"h12"*) or the 24-hour format (*"h23"*, *"h24"*) should be used. *"h11"* and *"h23"* start with hour 0 and go up to 11 and 23 respectively. *"h12"* and *"h24"* start with hour 1 and go up to 12 and 24. [[HourCycle]] is only used when [[Hour]] is not *undefined*.</li> | ||
| <li>[[DateStyle]], [[TimeStyle]] are each either *undefined*, or a String value with values *"full"*, *"long"*, *"medium"*, or *"short"*.</li> | ||
| <li>[[Pattern]] is a String value as described in <emu-xref href="#sec-intl.datetimeformat-internal-slots"></emu-xref>.</li> | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.