Skip to content

Commit 5c380df

Browse files
committed
Editorial: Merge CalendarDateAddition into CalendarDateAdd
Having two separate operations for this was already confusing just because of the names. Combine them into an ISO 8601 part and an implementation- defined part, as in CalendarDateToISO. See: #2948
1 parent 69e2d8e commit 5c380df

File tree

3 files changed

+13
-26
lines changed

3 files changed

+13
-26
lines changed

polyfill/lib/calendar.mjs

+1-3
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ impl['iso8601'] = {
174174
({ year, month } = ES.BalanceISOYearMonth(year, month));
175175
({ year, month, day } = ES.RegulateISODate(year, month, day, overflow));
176176
day += days + 7 * weeks;
177-
({ year, month, day } = ES.BalanceISODate(year, month, day));
178-
ES.RejectDateRange(year, month, day);
179-
return { year, month, day };
177+
return ES.BalanceISODate(year, month, day);
180178
},
181179
dateUntil(one, two, largestUnit) {
182180
const sign = -ES.CompareISODate(one.year, one.month, one.day, two.year, two.month, two.day);

polyfill/lib/ecmascript.mjs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1852,7 +1852,9 @@ export function CalendarMergeFields(calendar, fields, additionalFields) {
18521852
}
18531853

18541854
export function CalendarDateAdd(calendar, isoDate, dateDuration, overflow) {
1855-
return GetIntrinsic('%calendarImpl%')(calendar).dateAdd(isoDate, dateDuration, overflow);
1855+
const result = GetIntrinsic('%calendarImpl%')(calendar).dateAdd(isoDate, dateDuration, overflow);
1856+
RejectDateRange(result.year, result.month, result.day);
1857+
return result;
18561858
}
18571859

18581860
export function CalendarDateUntil(calendar, isoDate, isoOtherDate, largestUnit) {

spec/calendar.html

+9-22
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,7 @@ <h1>
418418
</emu-alg>
419419
</emu-clause>
420420

421-
<emu-clause id="sec-temporal-calendardateadd" type="abstract operation">
421+
<emu-clause id="sec-temporal-calendardateadd" type="implementation-defined abstract operation">
422422
<h1>
423423
CalendarDateAdd (
424424
_calendar_: a calendar type,
@@ -440,10 +440,15 @@ <h1>
440440
1. Set _intermediate_ to ? RegulateISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _isoDate_.[[Day]], _overflow_).
441441
1. Let _d_ be _intermediate_.[[Day]] + _duration_.[[Days]] + 7 × _duration_.[[Weeks]].
442442
1. Let _result_ be BalanceISODate(_intermediate_.[[Year]], _intermediate_.[[Month]], _d_).
443-
1. If ISODateWithinLimits(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *false*, throw a *RangeError* exception.
444-
1. Return _result_.
445-
1. Return ? CalendarDateAddition(_calendar_, _isoDate_, _duration_, _overflow_).
443+
1. Else,
444+
1. Let _result_ be an implementation-defined ISO Date Record, or throw a *RangeError* exception, as described below.
445+
1. If ISODateWithinLimits(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *false*, throw a *RangeError* exception.
446+
1. Return _result_.
446447
</emu-alg>
448+
<p>
449+
When _calendar_ is not *"iso8601"*, the operation performs implementation-defined processing to add _duration_ to _date_ in the context of the calendar represented by _calendar_ and returns the corresponding day, month and year of the result in the ISO 8601 calendar values as an ISO Date Record.
450+
It may throw a *RangeError* exception if _overflow_ is ~reject~ and the resulting month or day would need to be clamped in order to form a valid date in _calendar_.
451+
</p>
447452
</emu-clause>
448453

449454
<emu-clause id="sec-temporal-calendardateuntil" type="abstract operation">
@@ -1173,24 +1178,6 @@ <h1>
11731178
</p>
11741179
</emu-clause>
11751180

1176-
<emu-clause id="sec-temporal-calendardateaddition" type="implementation-defined abstract operation">
1177-
<h1>
1178-
CalendarDateAddition (
1179-
_calendar_: a calendar type that is not *"iso8601"*,
1180-
_date_: an ISO Date Record,
1181-
_duration_: a Date Duration Record,
1182-
_overflow_: ~constrain~ or ~reject~,
1183-
): either a normal completion containing an ISO Date Record or a throw completion
1184-
</h1>
1185-
<dl class="header">
1186-
<dt>description</dt>
1187-
<dd>
1188-
It performs implementation-defined processing to add _duration_ to _date_ in the context of the calendar represented by _calendar_ and returns the corresponding day, month and year of the result in the ISO 8601 calendar values as an ISO Date Record.
1189-
It may throw a *RangeError* exception if _overflow_ is ~reject~ and the resulting month or day would need to be clamped in order to form a valid date in _calendar_, or if the date resulting from the addition is outside the range allowed by ISODateTimeWithinLimits.
1190-
</dd>
1191-
</dl>
1192-
</emu-clause>
1193-
11941181
<emu-clause id="sec-temporal-calendardatedifference" type="implementation-defined abstract operation">
11951182
<h1>
11961183
CalendarDateDifference (

0 commit comments

Comments
 (0)