Skip to content

Commit

Permalink
Editorial: Add CreateTimeRecord AO
Browse files Browse the repository at this point in the history
Instead of writing out all the field names, add an abstract operation that
also encapsulates the IsValidTime assertion.

See: #2949

Co-authored-by: Ms2ger <[email protected]>
  • Loading branch information
ptomato and Ms2ger committed Oct 8, 2024
1 parent 86ff110 commit 607e263
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 50 deletions.
3 changes: 1 addition & 2 deletions spec/abstractops.html
Original file line number Diff line number Diff line change
Expand Up @@ -1520,11 +1520,10 @@ <h1>
1. Let _microsecondMV_ be 0.
1. Let _nanosecondMV_ be 0.
1. Assert: IsValidISODate(_yearMV_, _monthMV_, _dayMV_) is *true*.
1. Assert: IsValidTime(_hourMV_, _minuteMV_, _secondMV_, _millisecondMV_, _microsecondMV_, _nanosecondMV_) is *true*.
1. If _hour_ is empty, then
1. Let _time_ be ~start-of-day~.
1. Else,
1. Let _time_ be Time Record { [[Days]]: 0, [[Hour]]: _hourMV_, [[Minute]]: _minuteMV_, [[Second]]: _secondMV_, [[Millisecond]]: _millisecondMV_, [[Microsecond]]: _microsecondMV_, [[Nanosecond]]: _nanosecondMV_ }.
1. Let _time_ be CreateTimeRecord(_hourMV_, _minuteMV_, _secondMV_, _millisecondMV_, _microsecondMV_, _nanosecondMV_).
1. Let _timeZoneResult_ be ISO String Time Zone Parse Record { [[Z]]: *false*, [[OffsetString]]: ~empty~, [[TimeZoneAnnotation]]: ~empty~ }.
1. If _parseResult_ contains a |TimeZoneIdentifier| Parse Node, then
1. Let _identifier_ be the source text matched by the |TimeZoneIdentifier| Parse Node contained within _parseResult_.
Expand Down
4 changes: 2 additions & 2 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ <h1>Temporal.PlainDateTime ( _isoYear_, _isoMonth_, _isoDay_ [ , _hour_ [ , _min
1. If IsValidISODate(_isoYear_, _isoMonth_, _isoDay_) is *false*, throw a *RangeError* exception.
1. Let _isoDate_ be CreateISODateRecord(_isoYear_, _isoMonth_, _isoDay_).
1. If IsValidTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_) is *false*, throw a *RangeError* exception.
1. Let _time_ be Time Record { [[Hour]]: _hour_, [[Minute]]: _minute_, [[Second]]: _second_, [[Millisecond]]: _millisecond_, [[Microsecond]]: _microsecond_, [[Nanosecond]]: _nanosecond_ }.
1. Let _time_ be CreateTimeRecord(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
1. Let _isoDateTime_ be CombineISODateAndTimeRecord(_isoDate_, _time_).
1. Return ? CreateTemporalDateTime(_isoDateTime_, _calendar_, NewTarget).
</emu-alg>
Expand Down Expand Up @@ -718,7 +718,7 @@ <h1>
</dl>
<emu-alg>
1. Let _isoDate_ be CreateISODateRecord(ℝ(YearFromTime(_t_)), ℝ(MonthFromTime(_t_)) + 1, ℝ(DateFromTime(_t_))).
1. Let _time_ be Time Record { [[Days]]: 0, [[Hour]]: ℝ(HourFromTime(_t_)), [[Minute]]: ℝ(MinFromTime(_t_)), [[Second]]: ℝ(SecFromTime(_t_)), [[Millisecond]]: ℝ(msFromTime(_t_)), [[Microsecond]]: 0, [[Nanosecond]]: 0 }.
1. Let _time_ be CreateTimeRecord(ℝ(HourFromTime(_t_)), ℝ(MinFromTime(_t_)), ℝ(SecFromTime(_t_)), ℝ(msFromTime(_t_)), 0, 0).
1. Return ISO Date-Time Record { [[ISODate]]: _isoDate_, [[Time]]: _time_ }.
</emu-alg>
</emu-clause>
Expand Down
75 changes: 37 additions & 38 deletions spec/plaintime.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ <h1>Temporal.PlainTime ( [ _hour_ [ , _minute_ [ , _second_ [ , _millisecond_ [
1. If _microsecond_ is *undefined*, set _microsecond_ to 0; else set _microsecond_ to ? ToIntegerWithTruncation(_microsecond_).
1. If _nanosecond_ is *undefined*, set _nanosecond_ to 0; else set _nanosecond_ to ? ToIntegerWithTruncation(_nanosecond_).
1. If IsValidTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_) is *false*, throw a *RangeError* exception.
1. Let _time_ be Time Record { [[Hour]]: _hour_, [[Minute]]: _minute_, [[Second]]: _second_, [[Millisecond]]: _millisecond_, [[Microsecond]]: _microsecond_, [[Nanosecond]]: _nanosecond_ }.
1. Let _time_ be CreateTimeRecord(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
1. Return ? CreateTemporalTime(_time_, NewTarget).
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -445,6 +445,37 @@ <h1>Time Records</h1>
</emu-table>
</emu-clause>

<emu-clause id="sec-temporal-createtimerecord" type="abstract operation">
<h1>
CreateTimeRecord (
_hour_: an integer in the inclusive interval from 0 to 23,
_minute_: an integer in the inclusive interval from 0 to 59,
_second_: an integer in the inclusive interval from 0 to 59,
_millisecond_: an integer in the inclusive interval from 0 to 999,
_microsecond_: an integer in the inclusive interval from 0 to 999,
_nanosecond_: an integer in the inclusive interval from 0 to 999,
optional _deltaDays_: a non-negative integer,
): a Time Record
</h1>
<dl class="header">
<dt>description</dt>
<dd>Most uses of Time Records do not require the _deltaDays_ parameter.</dd>
</dl>
<emu-alg>
1. If _deltaDays_ is not present, set _deltaDays_ to 0.
1. Assert: IsValidTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
1. Return Time Record {
[[Days]]: _deltaDays_,
[[Hour]]: _hour_,
[[Minute]]: _minute_,
[[Second]]: _second_,
[[Millisecond]]: _millisecond_,
[[Microsecond]]: _microsecond_,
[[Nanosecond]]: _nanosecond_
}.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-midnighttimerecord" type="abstract operation">
<h1>MidnightTimeRecord ( ): a Time Record</h1>
<dl class="header">
Expand Down Expand Up @@ -592,15 +623,7 @@ <h1>
1. Else,
1. Assert: _overflow_ is ~reject~.
1. If IsValidTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_) is *false*, throw a *RangeError* exception.
1. Return Time Record {
[[Days]]: 0,
[[Hour]]: _hour_,
[[Minute]]: _minute_,
[[Second]]: _second_,
[[Millisecond]]: _millisecond_,
[[Microsecond]]: _microsecond_,
[[Nanosecond]]: _nanosecond_
}.
1. Return CreateTimeRecord(_hour_, _minute_, _second_, _millisecond_, _microsecond_,_nanosecond_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -665,17 +688,9 @@ <h1>
1. Set _second_ to _second_ modulo 60.
1. Set _hour_ to _hour_ + floor(_minute_ / 60).
1. Set _minute_ to _minute_ modulo 60.
1. Let _days_ be floor(_hour_ / 24).
1. Let _deltaDays_ be floor(_hour_ / 24).
1. Set _hour_ to _hour_ modulo 24.
1. Return Time Record {
[[Days]]: _days_,
[[Hour]]: _hour_,
[[Minute]]: _minute_,
[[Second]]: _second_,
[[Millisecond]]: _millisecond_,
[[Microsecond]]: _microsecond_,
[[Nanosecond]]: _nanosecond_
}.
1. Return CreateTimeRecord(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_, _deltaDays_).
</emu-alg>
</emu-clause>

Expand All @@ -701,15 +716,7 @@ <h1>
1. Set _millisecond_ to the result of clamping _millisecond_ between 0 and 999.
1. Set _microsecond_ to the result of clamping _microsecond_ between 0 and 999.
1. Set _nanosecond_ to the result of clamping _nanosecond_ between 0 and 999.
1. Return Time Record {
[[Days]]: 0,
[[Hour]]: _hour_,
[[Minute]]: _minute_,
[[Second]]: _second_,
[[Millisecond]]: _millisecond_,
[[Microsecond]]: _microsecond_,
[[Nanosecond]]: _nanosecond_
}.
1. Return CreateTimeRecord(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -911,15 +918,7 @@ <h1>
1. Let _unitLength_ be the value in the "Length in Nanoseconds" column of the row of <emu-xref href="#table-temporal-units"></emu-xref> whose "Value" column contains _unit_.
1. Let _result_ be RoundNumberToIncrement(_quantity_, _increment_ × _unitLength_, _roundingMode_) / _unitLength_.
1. If _unit_ is ~day~, then
1. Return Time Record {
[[Days]]: _result_,
[[Hour]]: 0,
[[Minute]]: 0,
[[Second]]: 0,
[[Millisecond]]: 0,
[[Microsecond]]: 0,
[[Nanosecond]]: 0
}.
1. Return CreateTimeRecord(0, 0, 0, 0, 0, 0, _result_).
1. If _unit_ is ~hour~, then
1. Return BalanceTime(_result_, 0, 0, 0, 0, 0).
1. If _unit_ is ~minute~, then
Expand Down
9 changes: 1 addition & 8 deletions spec/timezone.html
Original file line number Diff line number Diff line change
Expand Up @@ -73,14 +73,7 @@ <h1>
1. Assert: _microsecond_ &lt; 1000.
1. Let _nanosecond_ be _remainderNs_ modulo 1000.
1. Let _isoDate_ be CreateISODateRecord(_year_, _month_, _day_).
1. Let _time_ be Time Record {
[[Hour]]: _hour_,
[[Minute]]: _minute_,
[[Second]]: _second_,
[[Millisecond]]: _millisecond_,
[[Microsecond]]: _microsecond_,
[[Nanosecond]]: _nanosecond_
}.
1. Let _time_ be CreateTimeRecord(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_).
1. Return CombineISODateAndTimeRecord(_isoDate_, _time_).
</emu-alg>
</emu-clause>
Expand Down

0 comments on commit 607e263

Please sign in to comment.