Skip to content

Commit

Permalink
Editorial: Pass epoch nanoseconds to FormatDateTimePattern
Browse files Browse the repository at this point in the history
This simplifies the Temporal integration and makes FormatDateTimePattern
an infallible operation.
  • Loading branch information
anba authored and ben-allen committed Jul 13, 2024
1 parent 8cc4a81 commit 1780069
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions spec/datetimeformat.html
Original file line number Diff line number Diff line change
Expand Up @@ -1394,16 +1394,14 @@ <h1>
_dateTimeFormat_: an Intl.DateTimeFormat,
_format_: a DateTime Format Record or a DateTime Range Pattern Format Record,
_pattern_: a Pattern String,
_x_: a Number,
): either a normal completion containing a List of Records with fields [[Type]] (a String) and [[Value]] (a String), or a throw completion
_epochNanoseconds_: a BigInt,
): a List of Records with fields [[Type]] (a String) and [[Value]] (a String)
</h1>
<dl class="header">
<dt>description</dt>
<dd>It interprets _x_ as a time value as specified in es2024, <emu-xref href="#sec-time-values-and-time-range"></emu-xref>, and creates the corresponding parts according to _pattern_ and to the effective locale and the formatting options of _dateTimeFormat_ and _format_.</dd>
<dd>It creates the corresponding parts for the epoch time _epochNanoseconds_ according to _pattern_ and to the effective locale and the formatting options of _dateTimeFormat_ and _format_.</dd>
</dl>
<emu-alg>
1. Let _x_ be TimeClip(_x_).
1. If _x_ is *NaN*, throw a *RangeError* exception.
1. Let _locale_ be _dateTimeFormat_.[[Locale]].
1. Let _nfOptions_ be OrdinaryObjectCreate(*null*).
1. Perform ! CreateDataPropertyOrThrow(_nfOptions_, *"useGrouping"*, *false*).
Expand All @@ -1418,7 +1416,7 @@ <h1>
1. Perform ! CreateDataPropertyOrThrow(_nf3Options_, *"minimumIntegerDigits"*, 𝔽(_fractionalSecondDigits_)).
1. Perform ! CreateDataPropertyOrThrow(_nf3Options_, *"useGrouping"*, *false*).
1. Let _nf3_ be ! Construct(%Intl.NumberFormat%, &laquo; _locale_, _nf3Options_ &raquo;).
1. Let _tm_ be ToLocalTime(ℤ(ℝ(_x_) &times; 10<sup>6</sup>), _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _tm_ be ToLocalTime(_epochNanoseconds_, _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _patternParts_ be PartitionPattern(_pattern_).
1. Let _result_ be a new empty List.
1. For each Record { [[Type]], [[Value]] } _patternPart_ of _patternParts_, do
Expand Down Expand Up @@ -1482,7 +1480,7 @@ <h1>
1. Let _fv_ be an implementation and locale dependent String value representing _v_.
1. Append the Record { [[Type]]: *"yearName"*, [[Value]]: _fv_ } to _result_.
1. Else,
1. Let _unknown_ be an implementation-, locale-, and numbering system-dependent String based on _x_ and _p_.
1. Let _unknown_ be an implementation-, locale-, and numbering system-dependent String based on _epochNanoseconds_ and _p_.
1. Append the Record { [[Type]]: *"unknown"*, [[Value]]: _unknown_ } to _result_.
1. Return _result_.
</emu-alg>
Expand All @@ -1504,12 +1502,15 @@ <h1>
<dd>It interprets _x_ as a time value as specified in es2024, <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_.</dd>
</dl>
<emu-alg>
1. Let _x_ be TimeClip(_x_).
1. If _x_ is *NaN*, throw a *RangeError* exception.
1. Let _epochNanoseconds_ be ℤ(ℝ(_x_) &times; 10<sup>6</sup>).
1. Let _format_ be _dateTimeFormat_.[[DateTimeFormat]].
1. If _dateTimeFormat_.[[HourCycle]] is *"h11"* or *"h12"*, then
1. Let _pattern_ be _format_.[[pattern12]].
1. Else,
1. Let _pattern_ be _format_.[[pattern]].
1. Let _result_ be ? FormatDateTimePattern(_dateTimeFormat_, _format_, _pattern_, _x_).
1. Let _result_ be FormatDateTimePattern(_dateTimeFormat_, _format_, _pattern_, _epochNanoseconds_).
1. Return _result_.
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -1572,8 +1573,10 @@ <h1>
1. If _x_ is *NaN*, throw a *RangeError* exception.
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 _xEpochNanoseconds_ be ℤ(ℝ(_x_) &times; 10<sup>6</sup>).
1. Let _yEpochNanoseconds_ be ℤ(ℝ(_y_) &times; 10<sup>6</sup>).
1. Let _tm1_ be ToLocalTime(_xEpochNanoseconds_, _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _tm2_ be ToLocalTime(_yEpochNanoseconds_, _dateTimeFormat_.[[Calendar]], _dateTimeFormat_.[[TimeZone]]).
1. Let _format_ be _dateTimeFormat_.[[DateTimeFormat]].
1. If _dateTimeFormat_.[[HourCycle]] is *"h11"* or *"h12"*, then
1. Let _pattern_ be _format_.[[pattern12]].
Expand Down Expand Up @@ -1613,7 +1616,7 @@ <h1>
1. Set _relevantFieldsEqual_ to *false*.
1. If _relevantFieldsEqual_ is *true*, then
1. Let _collapsedResult_ be a new empty List.
1. Let _resultParts_ be ! FormatDateTimePattern(_dateTimeFormat_, _format_, _pattern_, _x_).
1. Let _resultParts_ be FormatDateTimePattern(_dateTimeFormat_, _format_, _pattern_, _xEpochNanoseconds_).
1. For each Record { [[Type]], [[Value]] } _r_ of _resultParts_, do
1. Append the Record { [[Type]]: _r_.[[Type]], [[Value]]: _r_.[[Value]], [[Source]]: *"shared"* } to _collapsedResult_.
1. Return _collapsedResult_.
Expand All @@ -1624,10 +1627,10 @@ <h1>
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. Let _z_ be _xEpochNanoseconds_.
1. Else,
1. Let _z_ be _y_.
1. Let _resultParts_ be ! FormatDateTimePattern(_dateTimeFormat_, _selectedRangePattern_, _pattern_, _z_).
1. Let _z_ be _yEpochNanoseconds_.
1. Let _resultParts_ be FormatDateTimePattern(_dateTimeFormat_, _selectedRangePattern_, _pattern_, _z_).
1. For each Record { [[Type]], [[Value]] } _r_ of _resultParts_, do
1. Append the Record { [[Type]]: _r_.[[Type]], [[Value]]: _r_.[[Value]], [[Source]]: _source_ } to _rangeResult_.
1. Return _rangeResult_.
Expand Down

0 comments on commit 1780069

Please sign in to comment.