Skip to content

Commit

Permalink
spec: compare methods should not include calendar
Browse files Browse the repository at this point in the history
This commit changes different compare methods on types that include
calendars to not take them into account. With this, two instances that
have different calendars attached but map to the same points in the ISO
calendar are compared to be "equal".

Fixes: tc39#1431
  • Loading branch information
ryzokuken committed Mar 22, 2021
1 parent fa38136 commit 13470da
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 26 deletions.
19 changes: 4 additions & 15 deletions spec/plaindate.html
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,7 @@ <h1>Temporal.PlainDate.compare ( _one_, _two_ )</h1>
<emu-alg>
1. Set _one_ to ? ToTemporalDate(_one_).
1. Set _two_ to ? ToTemporalDate(_two_).
1. Return 𝔽(? CompareTemporalDateCalendar(_one_.[[ISOYear]], _one_.[[ISOMonth]], _one_.[[ISODay]], _one_.[[Calendar]],
_two_.[[ISOYear]], _two_.[[ISOMonth]], _two_.[[ISODay]], _two_.[[Calendar]])).
1. Return 𝔽(! CompareTemporalDate(_one_.[[ISOYear]], _one_.[[ISOMonth]], _one_.[[ISODay]], _two_.[[ISOYear]], _two_.[[ISOMonth]], _two_.[[ISODay]])).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -775,7 +774,7 @@ <h1>DifferenceISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _largestUnit_ )</h1>
1. Set _years_ to 0.
1. Return the new Record { [[Years]]: _years_, [[Months]]: _months_, [[Weeks]]: 0, [[Days]]: _days_ }.
1. If _largestUnit_ is *"days"* or *"weeks"*, then
1. If ! CompareISODate(_y1_, _m1_, _d1_, _y2_, _m2_, _d2_) &lt; 0, then
1. If ! CompareTemporalDate(_y1_, _m1_, _d1_, _y2_, _m2_, _d2_) &lt; 0, then
1. Let _smaller_ be the new Record { [[Year]]: _y1_, [[Month]]: _m1_, [[Day]]: _d1_ }.
1. Let _greater_ be the new Record { [[Year]]: _y2_, [[Month]]: _m2_, [[Day]]: _d2_ }.
1. Let _sign_ be 1.
Expand Down Expand Up @@ -946,8 +945,8 @@ <h1>AddISODate ( _year_, _month_, _day_, _years_, _months_, _weeks_, _days_, _ov
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-compareisodate" aoid="CompareISODate">
<h1>CompareISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_ )</h1>
<emu-clause id="sec-temporal-comparetemporaldate" aoid="CompareTemporalDate">
<h1>CompareTemporalDate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_ )</h1>
<emu-alg>
1. If _y1_ &gt; _y2_, return 1.
1. If _y1_ &lt; _y2_, return -1.
Expand All @@ -958,15 +957,5 @@ <h1>CompareISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_ )</h1>
1. Return 0.
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-comparetemporaldatecalendar" aoid="CompareTemporalDateCalendar">
<h1>CompareTemporalDateCalendar ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _c1_, _c2_ )</h1>
<emu-alg>
1. Let _result_ be ! CompareISODate(_y1_, _m1_, _d1_, _y2_, _m2_, _d2_).
1. If _result_ ≠ 0, then
1. Return _result_.
1. Return ? CompareCalendar(_c1_, _c2_).
</emu-alg>
</emu-clause>
</emu-clause>
</emu-clause>
9 changes: 3 additions & 6 deletions spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,7 @@ <h1>Temporal.PlainDateTime.compare ( _one_, _two_ )</h1>
<emu-alg>
1. Set _one_ to ? ToTemporalDateTime(_one_).
1. Set _two_ to ? ToTemporalDateTime(_two_).
1. Let _result_ be ! CompareISODateTime(_one_.[[ISOYear]], _one_.[[ISOMonth]], _one_.[[ISODay]], _one_.[[ISOHour]], _one_.[[ISOMinute]], _one_.[[ISOSecond]], _one_.[[ISOMillisecond]], _one_.[[ISOMicrosecond]], _one_.[[ISONanosecond]], _two_.[[ISOYear]], _two_.[[ISOMonth]], _two_.[[ISODay]], _two_.[[ISOHour]], _two_.[[ISOMinute]], _two_.[[ISOSecond]], _two_.[[ISOMillisecond]], _two_.[[ISOMicrosecond]], _two_.[[ISONanosecond]]).
1. If _result_ ≠ 0, then
1. Return 𝔽(_result_).
1. Return 𝔽(? CompareCalendar(_one_.[[Calendar]], _two_.[[Calendar]])).
1. Return 𝔽(! CompareTemporalDateTime(_one_.[[ISOYear]], _one_.[[ISOMonth]], _one_.[[ISODay]], _one_.[[ISOHour]], _one_.[[ISOMinute]], _one_.[[ISOSecond]], _one_.[[ISOMillisecond]], _one_.[[ISOMicrosecond]], _one_.[[ISONanosecond]], _two_.[[ISOYear]], _two_.[[ISOMonth]], _two_.[[ISODay]], _two_.[[ISOHour]], _two_.[[ISOMinute]], _two_.[[ISOSecond]], _two_.[[ISOMillisecond]], _two_.[[ISOMicrosecond]], _two_.[[ISONanosecond]])).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -1082,8 +1079,8 @@ <h1>TemporalDateTimeToString ( _isoYear_, _isoMonth_, _isoDay_, _hour_, _minute_
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-compareisodatetime" aoid="CompareISODateTime">
<h1>CompareISODateTime ( _y1_, _mon1_, _d1_, _h1_, _min1_, _s1_, _ms1_, _mus1_, _ns1_, _y2_, _mon2_, _d2_, _h2_, _min2_, _s2_, _ms2_, _mus2_, _ns2_ )</h1>
<emu-clause id="sec-temporal-comparetemporaldatetime" aoid="CompareTemporalDateTime">
<h1>CompareTemporalDateTime ( _y1_, _mon1_, _d1_, _h1_, _min1_, _s1_, _ms1_, _mus1_, _ns1_, _y2_, _mon2_, _d2_, _h2_, _min2_, _s2_, _ms2_, _mus2_, _ns2_ )</h1>
<emu-alg>
1. If _y1_ &gt; _y2_, return 1.
1. If _y1_ &lt; _y2_, return -1.
Expand Down
3 changes: 1 addition & 2 deletions spec/plainyearmonth.html
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@ <h1>Temporal.PlainYearMonth.compare ( _one_, _two_ )</h1>
<emu-alg>
1. Set _one_ to ? ToTemporalYearMonth(_one_).
1. Set _two_ to ? ToTemporalYearMonth(_two_).
1. Return 𝔽(? CompareTemporalDateCalendar(_one_.[[ISOYear]], _one_.[[ISOMonth]], _one_.[[ISODay]], _one_.[[Calendar]],
_two_.[[ISOYear]], _two_.[[ISOMonth]], _two_.[[ISODay]], _two_.[[Calendar]])).
1. Return 𝔽(? CompareTemporalDate(_one_.[[ISOYear]], _one_.[[ISOMonth]], _one_.[[ISODay]], _two_.[[ISOYear]], _two_.[[ISOMonth]], _two_.[[ISODay]])).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down
3 changes: 0 additions & 3 deletions spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ <h1>Temporal.ZonedDateTime.compare ( _one_, _two_ )</h1>
1. Set _one_ to ? ToTemporalZonedDateTime(_one_).
1. Set _two_ to ? ToTemporalZonedDateTime(_two_).
1. Let _result_ be ! CompareEpochNanoseconds(_one_.[[Nanoseconds]], _two_.[[Nanoseconds]]).
1. If _result_ ≠ 0, then
1. Return 𝔽(_result_).
1. Set _result_ to ? CompareCalendar(_one_.[[Calendar]], _two_.[[Calendar]]).
1. If _result_ ≠ 0, then
1. Return 𝔽(_result_).
1. Return 𝔽(? CompareTimeZone(_one_.[[TimeZone]], _two_.[[TimeZone]]).
Expand Down

0 comments on commit 13470da

Please sign in to comment.