From 19e5ff9218ef3882f3bcd6330aa01bd449be1270 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Fri, 18 Jul 2025 19:44:31 -0700 Subject: [PATCH 1/3] Editorial: Rewrite CalendarDateUntil to be simpler and more general --- spec/calendar.html | 63 ++++++++++++++++++++-------------------------- 1 file changed, 27 insertions(+), 36 deletions(-) diff --git a/spec/calendar.html b/spec/calendar.html index 85c4f4310..07f48b5fe 100644 --- a/spec/calendar.html +++ b/spec/calendar.html @@ -525,42 +525,33 @@

- 1. If _calendar_ is *"iso8601"*, then - 1. Let _sign_ be -CompareISODate(_one_, _two_). - 1. If _sign_ = 0, return ZeroDateDuration(). - 1. Let _years_ be 0. - 1. If _largestUnit_ is ~year~, then - 1. Let _candidateYears_ be _sign_. - 1. Repeat, while ISODateSurpasses(_sign_, _one_.[[Year]] + _candidateYears_, _one_.[[Month]], _one_.[[Day]], _two_) is *false*, - 1. Set _years_ to _candidateYears_. - 1. Set _candidateYears_ to _candidateYears_ + _sign_. - 1. Let _months_ be 0. - 1. If _largestUnit_ is ~year~ or _largestUnit_ is ~month~, then - 1. Let _candidateMonths_ be _sign_. - 1. Let _intermediate_ be BalanceISOYearMonth(_one_.[[Year]] + _years_, _one_.[[Month]] + _candidateMonths_). - 1. Repeat, while ISODateSurpasses(_sign_, _intermediate_.[[Year]], _intermediate_.[[Month]], _one_.[[Day]], _two_) is *false*, - 1. Set _months_ to _candidateMonths_. - 1. Set _candidateMonths_ to _candidateMonths_ + _sign_. - 1. Set _intermediate_ to BalanceISOYearMonth(_intermediate_.[[Year]], _intermediate_.[[Month]] + _sign_). - 1. Set _intermediate_ to BalanceISOYearMonth(_one_.[[Year]] + _years_, _one_.[[Month]] + _months_). - 1. Let _constrained_ be ! RegulateISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _one_.[[Day]], ~constrain~). - 1. Let _weeks_ be 0. - 1. If _largestUnit_ is ~week~, then - 1. Let _candidateWeeks_ be _sign_. - 1. Set _intermediate_ to BalanceISODate(_constrained_.[[Year]], _constrained_.[[Month]], _constrained_.[[Day]] + 7 × _candidateWeeks_). - 1. Repeat, while ISODateSurpasses(_sign_, _intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]], _two_) is *false*, - 1. Set _weeks_ to _candidateWeeks_. - 1. Set _candidateWeeks_ to _candidateWeeks_ + sign. - 1. Set _intermediate_ to BalanceISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]] + 7 × _sign_). - 1. Let _days_ be 0. - 1. Let _candidateDays_ be _sign_. - 1. Set _intermediate_ to BalanceISODate(_constrained_.[[Year]], _constrained_.[[Month]], _constrained_.[[Day]] + 7 × _weeks_ + _candidateDays_). - 1. Repeat, while ISODateSurpasses(_sign_, _intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]], _two_) is *false*, - 1. Set _days_ to _candidateDays_. - 1. Set _candidateDays_ to _candidateDays_ + _sign_. - 1. Set _intermediate_ to BalanceISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]] + _sign_). - 1. Return ! CreateDateDurationRecord(_years_, _months_, _weeks_, _days_). - 1. Return an implementation-defined Date Duration Record as described above. + 1. Let _sign_ be -CompareISODate(_one_, _two_). + 1. If _sign_ = 0, return ZeroDateDuration(). + 1. Let _duration_ be CreateDateDurationRecord(0, 0, 0, 0). + 1. If _largestUnit_ is ~year~, then + 1. Let _intermediate_ be _one_. + 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, + 1. Set _duration_.[[Years]] to _duration_.[[Years]] + _sign_. + 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _duration_.[[Years]] to _duration_.[[Years]] - _sign_. + 1. If _largestUnit_ is ~year~ or _largestUnit_ is ~month~, then + 1. Let _intermediate_ be _one_. + 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, + 1. Set _duration_.[[Months]] to _duration_.[[Months]] + _sign_. + 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _duration_.[[Months]] to _duration_.[[Months]] - _sign_. + 1. If _largestUnit_ is ~week~, then + 1. Let _intermediate_ be _one_. + 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, + 1. Set _duration_.[[Weeks]] to _duration_.[[Weeks]] + _sign_. + 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _duration_.[[Weeks]] to _duration_.[[Weeks]] - _sign_. + 1. Let _intermediate_ be _one_. + 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, + 1. Set _duration_.[[Days]] to _duration_.[[Days]] + _sign_. + 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _duration_.[[Days]] to _duration_.[[Days]] - _sign_. + 1. Return ! _duration_. From ff2e31a49f2207fca00df4a128ca9e5e4b370999 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Fri, 18 Jul 2025 20:01:52 -0700 Subject: [PATCH 2/3] Add exclamation marks --- spec/calendar.html | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/calendar.html b/spec/calendar.html index 07f48b5fe..6e0fb6cbf 100644 --- a/spec/calendar.html +++ b/spec/calendar.html @@ -532,24 +532,24 @@

1. Let _intermediate_ be _one_. 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, 1. Set _duration_.[[Years]] to _duration_.[[Years]] + _sign_. - 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _intermediate_ to ! CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). 1. Set _duration_.[[Years]] to _duration_.[[Years]] - _sign_. 1. If _largestUnit_ is ~year~ or _largestUnit_ is ~month~, then 1. Let _intermediate_ be _one_. 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, 1. Set _duration_.[[Months]] to _duration_.[[Months]] + _sign_. - 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _intermediate_ to ! CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). 1. Set _duration_.[[Months]] to _duration_.[[Months]] - _sign_. 1. If _largestUnit_ is ~week~, then 1. Let _intermediate_ be _one_. 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, 1. Set _duration_.[[Weeks]] to _duration_.[[Weeks]] + _sign_. - 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _intermediate_ to ! CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). 1. Set _duration_.[[Weeks]] to _duration_.[[Weeks]] - _sign_. 1. Let _intermediate_ be _one_. 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_, 1. Set _duration_.[[Days]] to _duration_.[[Days]] + _sign_. - 1. Set _intermediate_ to CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). + 1. Set _intermediate_ to ! CalendarDateAdd(_calendar_, _one_, _duration_, ~constrain~). 1. Set _duration_.[[Days]] to _duration_.[[Days]] - _sign_. 1. Return ! _duration_. From 90041216437a9f8996cf5c6858dfc23066363568 Mon Sep 17 00:00:00 2001 From: "Shane F. Carr" Date: Fri, 18 Jul 2025 20:03:43 -0700 Subject: [PATCH 3/3] Add another exclamation mark --- spec/calendar.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/calendar.html b/spec/calendar.html index 6e0fb6cbf..3073b0327 100644 --- a/spec/calendar.html +++ b/spec/calendar.html @@ -527,7 +527,7 @@

1. Let _sign_ be -CompareISODate(_one_, _two_). 1. If _sign_ = 0, return ZeroDateDuration(). - 1. Let _duration_ be CreateDateDurationRecord(0, 0, 0, 0). + 1. Let _duration_ be ! CreateDateDurationRecord(0, 0, 0, 0). 1. If _largestUnit_ is ~year~, then 1. Let _intermediate_ be _one_. 1. Repeat, while CompareISODate(_intermediate_, _two_) != _sign_,