From 9df852675009570a8fd5378a4ebddd4a59d905ea Mon Sep 17 00:00:00 2001 From: Ujjwal Sharma Date: Mon, 22 Mar 2021 09:42:33 +0530 Subject: [PATCH] spec: compare methods should not include calendar 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: https://github.com/tc39/proposal-temporal/issues/1431 --- spec/plaindate.html | 21 +++++---------------- spec/plaindatetime.html | 5 +---- spec/plainyearmonth.html | 3 +-- spec/zoneddatetime.html | 3 --- 4 files changed, 7 insertions(+), 25 deletions(-) diff --git a/spec/plaindate.html b/spec/plaindate.html index 66870220a7..d2ef81d474 100644 --- a/spec/plaindate.html +++ b/spec/plaindate.html @@ -83,8 +83,7 @@

Temporal.PlainDate.compare ( _one_, _two_ )

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]])). @@ -740,13 +739,13 @@

DifferenceISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _largestUnit_ )

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 }. @@ -755,7 +754,7 @@

DifferenceISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _largestUnit_ )

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 }. @@ -765,7 +764,7 @@

DifferenceISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _largestUnit_ )

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_ < 0, set _days_ to -_mid_.[[Day]] - (! ISODaysInMonth(_end_.[[Year]], _end_.[[Month]]) - _end_.[[Day]]). @@ -958,15 +957,5 @@

CompareISODate ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_ )

1. Return 0. - - -

CompareTemporalDateCalendar ( _y1_, _m1_, _d1_, _y2_, _m2_, _d2_, _c1_, _c2_ )

- - 1. Let _result_ be ! CompareISODate(_y1_, _m1_, _d1_, _y2_, _m2_, _d2_). - 1. If _result_ ≠ 0, then - 1. Return _result_. - 1. Return ? CompareCalendar(_c1_, _c2_). - -
diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html index 58a2f9d5fc..f416ac8c50 100644 --- a/spec/plaindatetime.html +++ b/spec/plaindatetime.html @@ -89,10 +89,7 @@

Temporal.PlainDateTime.compare ( _one_, _two_ )

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]])). diff --git a/spec/plainyearmonth.html b/spec/plainyearmonth.html index dc98f0a037..459d24a390 100644 --- a/spec/plainyearmonth.html +++ b/spec/plainyearmonth.html @@ -84,8 +84,7 @@

Temporal.PlainYearMonth.compare ( _one_, _two_ )

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]])). diff --git a/spec/zoneddatetime.html b/spec/zoneddatetime.html index c1bd3b0425..4c81d87fa2 100644 --- a/spec/zoneddatetime.html +++ b/spec/zoneddatetime.html @@ -87,9 +87,6 @@

Temporal.ZonedDateTime.compare ( _one_, _two_ )

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]]).