Skip to content

Commit eddb77f

Browse files
sffcptomato
authored andcommitted
Editorial: Move regulating and balancing logic into ISODateSurpasses
1 parent 47042f2 commit eddb77f

File tree

2 files changed

+22
-17
lines changed

2 files changed

+22
-17
lines changed

spec/calendar.html

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -563,34 +563,26 @@ <h1>
563563
1. Let _years_ be 0.
564564
1. If _largestUnit_ is ~year~, then
565565
1. Let _candidateYears_ be _sign_.
566-
1. Repeat, while ISODateSurpasses(_sign_, _one_.[[Year]] + _candidateYears_, _one_.[[Month]], _one_.[[Day]], _two_) is *false*,
566+
1. Repeat, while ISODateSurpasses(_sign_, _one_, _two_, _candidateYears_, 0, 0, 0) is *false*,
567567
1. Set _years_ to _candidateYears_.
568568
1. Set _candidateYears_ to _candidateYears_ + _sign_.
569569
1. Let _months_ be 0.
570570
1. If _largestUnit_ is ~year~ or _largestUnit_ is ~month~, then
571571
1. Let _candidateMonths_ be _sign_.
572-
1. Let _intermediate_ be BalanceISOYearMonth(_one_.[[Year]] + _years_, _one_.[[Month]] + _candidateMonths_).
573-
1. Repeat, while ISODateSurpasses(_sign_, _intermediate_.[[Year]], _intermediate_.[[Month]], _one_.[[Day]], _two_) is *false*,
572+
1. Repeat, while ISODateSurpasses(_sign_, _one_, _two_, _years_, _candidateMonths_, 0, 0) is *false*,
574573
1. Set _months_ to _candidateMonths_.
575574
1. Set _candidateMonths_ to _candidateMonths_ + _sign_.
576-
1. Set _intermediate_ to BalanceISOYearMonth(_intermediate_.[[Year]], _intermediate_.[[Month]] + _sign_).
577-
1. Set _intermediate_ to BalanceISOYearMonth(_one_.[[Year]] + _years_, _one_.[[Month]] + _months_).
578-
1. Let _constrained_ be ! RegulateISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _one_.[[Day]], ~constrain~).
579575
1. Let _weeks_ be 0.
580576
1. If _largestUnit_ is ~week~, then
581577
1. Let _candidateWeeks_ be _sign_.
582-
1. Set _intermediate_ to BalanceISODate(_constrained_.[[Year]], _constrained_.[[Month]], _constrained_.[[Day]] + 7 × _candidateWeeks_).
583-
1. Repeat, while ISODateSurpasses(_sign_, _intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]], _two_) is *false*,
578+
1. Repeat, while ISODateSurpasses(_sign_, _one_, _two_, _years_, _months_, _candidateWeeks_, 0) is *false*,
584579
1. Set _weeks_ to _candidateWeeks_.
585580
1. Set _candidateWeeks_ to _candidateWeeks_ + sign.
586-
1. Set _intermediate_ to BalanceISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]] + 7 × _sign_).
587581
1. Let _days_ be 0.
588582
1. Let _candidateDays_ be _sign_.
589-
1. Set _intermediate_ to BalanceISODate(_constrained_.[[Year]], _constrained_.[[Month]], _constrained_.[[Day]] + 7 × _weeks_ + _candidateDays_).
590-
1. Repeat, while ISODateSurpasses(_sign_, _intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]], _two_) is *false*,
583+
1. Repeat, while ISODateSurpasses(_sign_, _one_, _two_, _years_, _months_, _weeks_, _candidateDays_) is *false*,
591584
1. Set _days_ to _candidateDays_.
592585
1. Set _candidateDays_ to _candidateDays_ + _sign_.
593-
1. Set _intermediate_ to BalanceISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _intermediate_.[[Day]] + _sign_).
594586
1. Return ! CreateDateDurationRecord(_years_, _months_, _weeks_, _days_).
595587
1. Return NonISODateUntil(_calendar_, _one_, _two_, _largestUnit_).
596588
</emu-alg>

spec/plaindate.html

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -694,21 +694,34 @@ <h1>
694694
<h1>
695695
ISODateSurpasses (
696696
_sign_: -1 or 1,
697-
_y1_: an integer,
698-
_m1_: an integer,
699-
_d1_: an integer,
697+
_baseDate_: an ISO Date Record,
700698
_isoDate2_: an ISO Date Record,
699+
_years_: an integer,
700+
_months_: an integer,
701+
_weeks_: an integer,
702+
_days_: an integer,
701703
): a Boolean
702704
</h1>
703705
<dl class="header">
704706
<dt>description</dt>
705707
<dd>
706-
The return value indicates whether the date denoted by _y1_, _m1_, _d1_ surpasses that denoted by _isoDate2_ in the direction denoted by _sign_.
707-
The former date does not have to exist.
708+
The return value indicates whether the date _isoDate1_, the result of adding the duration denoted by _years_, _months_, _weeks_, and _days_ to _baseDate_, surpasses _isoDate2_ in the direction denoted by _sign_.
709+
If _weeks_ and _days_ are both zero, then _isoDate1_ need not exist (for example, it could be February 30).
708710
Note that this operation is specific to date difference calculations and is not the same as CompareISODate.
709711
</dd>
710712
</dl>
711713
<emu-alg>
714+
1. Let _yearMonth_ be BalanceISOYearMonth(_baseDate_.[[Year]] + _years_, _baseDate_.[[Month]] + _months_).
715+
1. If _weeks_ is not 0 or _days_ is not 0, then
716+
1. Let _regulatedDate_ be ! RegulateISODate(_yearMonth_.[[Year]], _yearMonth_.[[Month]], _baseDate_.[[Day]], ~constrain~).
717+
1. Let _balancedDate_ be BalanceISODate(_regulatedDate_.[[Year]], _regulatedDate_.[[Month]], _regulatedDate_.[[Day]] + 7 * _weeks_ + _days_).
718+
1. Let _y1_ be _balancedDate_.[[Year]].
719+
1. Let _m1_ be _balancedDate_.[[Month]].
720+
1. Let _d1_ be _balancedDate_.[[Day]].
721+
1. Else,
722+
1. Let _y1_ be _yearMonth_.[[Year]].
723+
1. Let _m1_ be _yearMonth_.[[Month]].
724+
1. Let _d1_ be _baseDate_.[[Day]].
712725
1. If _y1__isoDate2_.[[Year]], then
713726
1. If _sign_ × (_y1_ - _isoDate2_.[[Year]]) > 0, return *true*.
714727
1. Else if _m1__isoDate2_.[[Month]], then

0 commit comments

Comments
 (0)