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: #1431
  • Loading branch information
ryzokuken authored and ptomato committed Mar 23, 2021
1 parent fa38136 commit 9df8526
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
21 changes: 5 additions & 16 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 𝔽(! CompareISODate(_one_.[[ISOYear]], _one_.[[ISOMonth]], _one_.[[ISODay]], _two_.[[ISOYear]], _two_.[[ISOMonth]], _two_.[[ISODay]])).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down Expand Up @@ -740,13 +739,13 @@ <h1>DifferenceISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _largestUnit_ )</h1>
1. If _largestUnit_ is not *"years"*, *"months"*, or *"weeks"*, then
1. Set _largestUnit_ to *"days"*.
1. If _largestUnit_ is *"years"* or *"months"*, then
1. Let _sign_ be -(! ES.CompareTemporalDate(_y1_, _m1_, _d1_, _y2_, _m2_, _d2_)).
1. Let _sign_ be -(! CompareISODate(_y1_, _m1_, _d1_, _y2_, _m2_, _d2_)).
1. If _sign_ is 0, return the new Record { [[Years]]: 0, [[Months]]: 0, [[Weeks]]: 0, [[Days]]: 0 }.
1. Let _start_ be the new Record { [[Year]]: _y1_, [[Month]]: _m1_, [[Day]]: _d1_ }.
1. Let _end_ be the new Record { [[Year]]: _y2_, [[Month]]: _m2_, [[Day]]: _d2_ }.
1. Let _years_ be _end_.[[Year]] − _start_.[[Year]].
1. Let _mid_ be ? AddISODate(_y1_, _m1_, _d1_, _years_, 0, 0, *"constrain"*).
1. Let _midSign_ be -(! ES.CompareTemporalDate(_mid_.[[Year]], _mid_.[[Month]], _mid_.[[Day]], _y2_, _m2_, _d2_)).
1. Let _midSign_ be -(! CompareISODate(_mid_.[[Year]], _mid_.[[Month]], _mid_.[[Day]], _y2_, _m2_, _d2_)).
1. If _midSign_ is 0, then
1. If _largestUnit_ is *"years"*, return the new Record { [[Years]]: _years_, [[Months]]: 0, [[Weeks]]: 0, [[Days]]: 0 }.
1. Else, return the new Record { [[Years]]: 0, [[Months]]: _years_ × 12, [[Weeks]]: 0, [[Days]]: 0 }.
Expand All @@ -755,7 +754,7 @@ <h1>DifferenceISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _largestUnit_ )</h1>
1. Set _years_ to _years_ - _sign_.
1. Set _months_ to _months_ + _sign_ × 12.
1. Set _mid_ be ? AddISODate(_y1_, _m1_, _d1_, _years_, _months_, 0, *"constrain"*).
1. Let _midSign_ be -(! ES.CompareTemporalDate(_mid_.[[Year]], _mid_.[[Month]], _mid_.[[Day]], _y2_, _m2_, _d2_)).
1. Let _midSign_ be -(! CompareISODate(_mid_.[[Year]], _mid_.[[Month]], _mid_.[[Day]], _y2_, _m2_, _d2_)).
1. If _midSign_ is 0, then
1. If _largestUnit_ is *"years"*, return the new Record { [[Years]]: _years_, [[Months]]: _months_, [[Weeks]]: 0, [[Days]]: 0 }.
1. Else, return the new Record { [[Years]]: 0, [[Months]]: _months_ + _years_ × 12, [[Weeks]]: 0, [[Days]]: 0 }.
Expand All @@ -765,7 +764,7 @@ <h1>DifferenceISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _largestUnit_ )</h1>
1. Set _years_ to _years_ - _sign_.
1. Set _months_ to 11 × _sign_.
1. Set _mid_ be ? AddISODate(_y1_, _m1_, _d1_, _years_, _months_, 0, *"constrain"*).
1. Let _midSign_ be -(! ES.CompareTemporalDate(_mid_.[[Year]], _mid_.[[Month]], _mid_.[[Day]], _y2_, _m2_, _d2_)).
1. Let _midSign_ be -(! CompareISODate(_mid_.[[Year]], _mid_.[[Month]], _mid_.[[Day]], _y2_, _m2_, _d2_)).
1. Let _days_ be 0.
1. If _mid_.[[Month]] is equal to _end_.[[Month]] and _mid_.[[Year]] is equal to _mid_.[[Year]], set _days_ to _end_.[[Day]] - _mid_.[[Day]].
1. Else if _sign_ &lt; 0, set _days_ to -_mid_.[[Day]] - (! ISODaysInMonth(_end_.[[Year]], _end_.[[Month]]) - _end_.[[Day]]).
Expand Down Expand Up @@ -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>
5 changes: 1 addition & 4 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 𝔽(! 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]])).
</emu-alg>
</emu-clause>
</emu-clause>
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 𝔽(? CompareISODate(_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 9df8526

Please sign in to comment.