Skip to content

Commit 8a4c34a

Browse files
committed
Rewrite NonISODateAdd with new AOs
1 parent 6d6e82d commit 8a4c34a

File tree

1 file changed

+30
-13
lines changed

1 file changed

+30
-13
lines changed

spec.emu

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -902,20 +902,16 @@ contributors: Google, Ecma International
902902
<p>This definition supersedes the definition provided in <emu-xref href="#sec-temporal-nonisodateadd"></emu-xref>.</p>
903903
<p>It performs the following steps when called:</p>
904904
<emu-alg>
905-
1. Let _calendarDate_ be CalendarISOToDate(_calendar_, _isoDate_).
906-
1. Add _duration_.[[Years]] to _calendarDate_.
907-
1. (This step only matters for lunisolar calendars.) If _calendarDate_.[[MonthCode]] is a leap month that doesn't exist in the year, then:
908-
1. Set _calendarDate_ to another date according to the cultural conventions of that calendar's users. Of the currently supported calendars: if _calendar_ is *"chinese"* or *"dangi"*, change _calendarDate_.[[MonthCode]] to the same month code but without the *"L"*. If _calendar_ is *"hebrew"*, change _calendarDate_.[[MonthCode]] from *"M05L"* to *"M06"*.
909-
1. Update _calendarDate_.[[Month]] accordingly.
910-
1. Add _duration_.[[Months]] to _calendarDate_, balancing _calendarDate_ if it goes over a year boundary.
911-
1. If the date described by _calendarDate_ does not exist, then
905+
1. Let _yearMonth_ be RegulateNonISOYearMonth(_calendar_, _isoDate_, _years_).
906+
1. Let _endOfMonth_ be BalanceNonISODate(_calendar_, _yearMonth_.[[Year]], _yearMonth_.[[Month]] + _months_ + 1, 0).
907+
1. Let _baseDay_ be CalendarISOToDate(_calendar_, _isoDate_).[[Day]].
908+
1. If _endOfMonth_.[[Day]] &lt; _baseDay_, then
912909
1. If _overflow_ is ~reject~, throw a *RangeError* exception.
913-
1. If _calendarDate_.[[MonthCode]] is a valid month code for _calendarDate_.[[Year]], but the date described by _calendarDate_ does not exist, set _calendarDate_.[[Day]] to the closest day in the same month. If there are two equally-close dates in the same month, pick the later one.
914-
1. (This step does not apply to any currently supported calendars.) If the date described by _calendarDate_ still does not exist, set _calendarDate_ to the closest date in the same year. If there are two equally-close dates in that year, pick the later one.
915-
1. Add _duration_.[[Weeks]] and _duration_.[[Days]] to _calendarDate_, balancing _calendarDate_ if it goes over a month or year boundary.
916-
1. Let _result_ be ? CalendarDateToISO(_calendar_, _calendarDate_, _overflow_).
917-
1. If ISODateWithinLimits(_result_) is *false*, throw a *RangeError* exception.
918-
1. Return _result_.
910+
1. Let _regulatedDay_ be _endOfMonth_.[[Day]].
911+
1. Else,
912+
1. Let _regulatedDay_ be _baseDay_.
913+
1. Let _balancedDate_ be BalanceNonISODate(_calendar_, _endOfMonth_.[[Year]], _endOfMonth_.[[Month]], _regulatedDay_ + 7 * _duration_.[[Weeks]] + _duration_.[[Days]]).
914+
1. Return CalendarDateArithmeticalToISO(_balancedDate_.[[Year]], _balancedDate_.[[Month]], _balancedDate_.[[Day]]).
919915
</emu-alg>
920916
</emu-clause>
921917

@@ -1014,6 +1010,27 @@ contributors: Google, Ecma International
10141010
</emu-alg>
10151011
</emu-clause>
10161012

1013+
<emu-clause id="sup-temporal-calendardatecodestoiso" type="implementation-defined abstract operation">
1014+
<h1>
1015+
CalendarDateArithmeticalToISO (
1016+
_calendar_: a calendar type that is not *"iso8601"*,
1017+
_year_: an integer,
1018+
_month_: an integer,
1019+
_day_: an integer,
1020+
): either a normal completion containing an ISO Date Record or a throw completion
1021+
</h1>
1022+
<dl class="header">
1023+
<dt>description</dt>
1024+
<dd>
1025+
It returns an ISO Date Record that, when converted to a Calendar Date Record with _calendar_ (for example, with CalendarISOToDate), contains the given _year_, _month_, and _day_ values in its [[Year]], [[Month]], and [[Day]] fields. If this is not possible, a RangeError is thrown.
1026+
</dd>
1027+
</dl>
1028+
<p>It performs the following steps when called:</p>
1029+
<emu-alg>
1030+
Returns a calendar-dependent completion as described above.
1031+
</emu-alg>
1032+
</emu-clause>
1033+
10171034
<emu-clause id="sup-temporal-calendardaysinmonth" type="implementation-defined abstract operation">
10181035
<h1>
10191036
CalendarDaysInMonth (

0 commit comments

Comments
 (0)