Skip to content
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

Editorial: Improve PartitionDateTimeRangePattern #773

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 33 additions & 39 deletions spec/datetimeformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -1049,71 +1049,65 @@ <h1>PartitionDateTimeRangePattern ( _dateTimeFormat_, _x_, _y_ )</h1>
The PartitionDateTimeRangePattern abstract operation is called with arguments _dateTimeFormat_ (which must be an object initialized as a DateTimeFormat), _x_ (which must be a Number value) and _y_ (which must be a Number value), interprets _x_ and _y_ as time values as specified in es2023, <emu-xref href="#sec-time-values-and-time-range"></emu-xref>, and creates the corresponding parts according to the effective locale and the formatting options of _dateTimeFormat_. The following steps are taken:
</p>
<emu-alg>
1. Let _x_ be TimeClip(_x_).
1. Set _x_ to TimeClip(_x_).
1. If _x_ is *NaN*, throw a *RangeError* exception.
1. Let _y_ be TimeClip(_y_).
1. Set _y_ to TimeClip(_y_).
1. If _y_ is *NaN*, throw a *RangeError* exception.
1. Let _tm1_ be ToLocalTime(ℤ(ℝ(_x_) &times; 10<sup>6</sup>), _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _tm2_ be ToLocalTime(ℤ(ℝ(_y_) &times; 10<sup>6</sup>), _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _rangePatterns_ be _dateTimeFormat_.[[RangePatterns]].
1. Let _rangePattern_ be *undefined*.
1. Let _dateFieldsPracticallyEqual_ be *true*.
1. Let _patternContainsLargerDateField_ be *false*.
1. While _dateFieldsPracticallyEqual_ is *true* and _patternContainsLargerDateField_ is *false*, repeat for each row of <emu-xref href="#table-datetimeformat-rangepatternfields"></emu-xref> in order, except the header row:
1. Let _selectedRangePattern_ be *undefined*.
1. Let _relevantFieldsEqual_ be *true*.
1. Let _checkMoreFields_ be *true*.
1. For each row of <emu-xref href="#table-datetimeformat-rangepatternfields"></emu-xref>, except the header row, in table order, do
1. Let _fieldName_ be the name given in the Range Pattern Field column of the row.
1. If _rangePatterns_ has a field [[&lt;_fieldName_&gt;]], let _rp_ be _rangePatterns_.[[&lt;_fieldName_&gt;]]; else let _rp_ be *undefined*.
1. If _rangePattern_ is not *undefined* and _rp_ is *undefined*, then
1. Set _patternContainsLargerDateField_ to *true*.
1. Else,
1. Let _rangePattern_ be _rp_.
1. If _rangePatterns_ has a field [[&lt;_fieldName_&gt;]], let _rangePattern_ be _rangePatterns_.[[&lt;_fieldName_&gt;]]; else let _rangePattern_ be *undefined*.
1. If _selectedRangePattern_ is not *undefined* and _rangePattern_ is *undefined*, then
1. NOTE: Because there is no range pattern for differences at or below this field, no further checks will be performed.
1. Set _checkMoreFields_ to *false*.
1. If _relevantFieldsEqual_ is *true* and _checkMoreFields_ is *true*, then
1. Set _selectedRangePattern_ to _rangePattern_.
1. If _fieldName_ is equal to [[AmPm]], then
1. Let _v1_ be _tm1_.[[Hour]].
1. Let _v2_ be _tm2_.[[Hour]].
1. If _v1_ is greater than 11 and _v2_ less or equal than 11, or _v1_ is less or equal than 11 and _v2_ is greater than 11, then
1. Set _dateFieldsPracticallyEqual_ to *false*.
1. If _tm1_.[[Hour]] is less than 12, let _v1_ be *"am"*; else let _v1_ be *"pm"*.
1. If _tm2_.[[Hour]] is less than 12, let _v2_ be *"am"*; else let _v2_ be *"pm"*.
1. Else if _fieldName_ is equal to [[DayPeriod]], then
1. Let _v1_ be a String value representing the day period of _tm1_; the String value depends upon the implementation and the effective locale of _dateTimeFormat_.
1. Let _v2_ be a String value representing the day period of _tm2_; the String value depends upon the implementation and the effective locale of _dateTimeFormat_.
1. If _v1_ is not equal to _v2_, then
1. Set _dateFieldsPracticallyEqual_ to *false*.
1. Else if _fieldName_ is equal to [[FractionalSecondDigits]], then
1. Let _fractionalSecondDigits_ be _dateTimeFormat_.[[FractionalSecondDigits]].
1. If _fractionalSecondDigits_ is *undefined*, then
1. Set _fractionalSecondDigits_ to 3.
1. Let _v1_ be _tm1_.[[Millisecond]].
1. Let _v2_ be _tm2_.[[Millisecond]].
1. Let _v1_ be floor(_v1_ &times; 10<sup>( _fractionalSecondDigits_ - 3 )</sup>).
1. Let _v2_ be floor(_v2_ &times; 10<sup>( _fractionalSecondDigits_ - 3 )</sup>).
1. If _v1_ is not equal to _v2_, then
1. Set _dateFieldsPracticallyEqual_ to *false*.
1. Let _exp_ be _fractionalSecondDigits_ - 3.
1. Let _v1_ be floor(_tm1_.[[Millisecond]] &times; 10<sup>_exp_</sup>).
1. Let _v2_ be floor(_tm2_.[[Millisecond]] &times; 10<sup>_exp_</sup>).
1. Else,
1. Let _v1_ be _tm1_.[[&lt;_fieldName_&gt;]].
1. Let _v2_ be _tm2_.[[&lt;_fieldName_&gt;]].
1. If _v1_ is not equal to _v2_, then
1. Set _dateFieldsPracticallyEqual_ to *false*.
1. If _dateFieldsPracticallyEqual_ is *true*, then
1. If _v1_ is not equal to _v2_, then
1. Set _relevantFieldsEqual_ to *false*.
1. If _relevantFieldsEqual_ is *true*, then
1. Let _collapsedResult_ be a new empty List.
1. Let _pattern_ be _dateTimeFormat_.[[Pattern]].
1. Let _patternParts_ be PartitionPattern(_pattern_).
1. Let _result_ be ? FormatDateTimePattern(_dateTimeFormat_, _patternParts_, _x_, *undefined*).
1. For each Record { [[Type]], [[Value]] } _r_ in _result_, do
1. Set _r_.[[Source]] to *"shared"*.
1. Return _result_.
1. Let _result_ be a new empty List.
1. If _rangePattern_ is *undefined*, then
1. Let _rangePattern_ be _rangePatterns_.[[Default]].
1. For each Record { [[Pattern]], [[Source]] } _rangePatternPart_ in _rangePattern_.[[PatternParts]], do
1. Let _resultParts_ be ? FormatDateTimePattern(_dateTimeFormat_, _patternParts_, _x_, *undefined*).
1. For each Record { [[Type]], [[Value]] } _r_ in _resultParts_, do
1. Append a new Record { [[Type]]: _r_.[[Type]], [[Value]]: _r_.[[Value]], [[Source]]: *"shared"* } as the last element of _collapsedResult_.
1. Return _collapsedResult_.
1. Let _rangeResult_ be a new empty List.
1. If _selectedRangePattern_ is *undefined*, then
1. Set _selectedRangePattern_ to _rangePatterns_.[[Default]].
1. For each Record { [[Pattern]], [[Source]] } _rangePatternPart_ in _selectedRangePattern_.[[PatternParts]], do
1. Let _pattern_ be _rangePatternPart_.[[Pattern]].
1. Let _source_ be _rangePatternPart_.[[Source]].
1. If _source_ is *"startRange"* or *"shared"*, then
1. Let _z_ be _x_.
1. Else,
1. Let _z_ be _y_.
1. Let _patternParts_ be PartitionPattern(_pattern_).
1. Let _partResult_ be ? FormatDateTimePattern(_dateTimeFormat_, _patternParts_, _z_, _rangePattern_).
1. For each Record { [[Type]], [[Value]] } _r_ in _partResult_, do
1. Set _r_.[[Source]] to _source_.
1. Add all elements in _partResult_ to _result_ in order.
1. Return _result_.
1. Let _resultParts_ be ? FormatDateTimePattern(_dateTimeFormat_, _patternParts_, _z_, _selectedRangePattern_).
1. For each Record { [[Type]], [[Value]] } _r_ in _resultParts_, do
1. Append a new Record { [[Type]]: _r_.[[Type]], [[Value]]: _r_.[[Value]], [[Source]]: _source_ } as the last element of _rangeResult_.
1. Return _rangeResult_.
</emu-alg>
</emu-clause>

Expand Down