diff --git a/spec/duration.html b/spec/duration.html
index 9587149683..fbe3935d11 100644
--- a/spec/duration.html
+++ b/spec/duration.html
@@ -383,11 +383,7 @@
Temporal.Duration.prototype.add ( _other_ [ , _options_ ] )
1. Let _duration_ be the *this* value.
1. Perform ? RequireInternalSlot(_duration_, [[InitializedTemporalDuration]]).
- 1. Set _other_ to ? ToTemporalDurationRecord(_other_).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
- 1. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _other_.[[Years]], _other_.[[Months]], _other_.[[Weeks]], _other_.[[Days]], _other_.[[Hours]], _other_.[[Minutes]], _other_.[[Seconds]], _other_.[[Milliseconds]], _other_.[[Microseconds]], _other_.[[Nanoseconds]], _relativeTo_).
- 1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
+ 1. Return ? AddDurationToOrSubtractDurationFromDuration(~add~, _duration_, _other_, _options_).
@@ -400,11 +396,7 @@ Temporal.Duration.prototype.subtract ( _other_ [ , _options_ ] )
1. Let _duration_ be the *this* value.
1. Perform ? RequireInternalSlot(_duration_, [[InitializedTemporalDuration]]).
- 1. Set _other_ to ? ToTemporalDurationRecord(_other_).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
- 1. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], -_other_.[[Years]], -_other_.[[Months]], -_other_.[[Weeks]], -_other_.[[Days]], -_other_.[[Hours]], -_other_.[[Minutes]], -_other_.[[Seconds]], -_other_.[[Milliseconds]], -_other_.[[Microseconds]], -_other_.[[Nanoseconds]], _relativeTo_).
- 1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
+ 1. Return ? AddDurationToOrSubtractDurationFromDuration(~subtract~, _duration_, _other_, _options_).
@@ -1847,5 +1839,28 @@
1. Return _result_.
+
+
+
+ AddDurationToOrSubtractDurationFromDuration (
+ _operation_: ~add~ or ~subtract~,
+ _duration_: a Temporal.Duration,
+ _other_: an ECMAScript language value,
+ _options_: an ECMAScript language value,
+ ): either a normal completion containing a Temporal.Duration or an abrupt completion
+
+
+
+ 1. If _operation_ is ~subtract~, let _sign_ be -1. Otherwise, let _sign_ be 1.
+ 1. Set _other_ to ? ToTemporalDurationRecord(_other_).
+ 1. Set _options_ to ? GetOptionsObject(_options_).
+ 1. Let _relativeTo_ be ? ToRelativeTemporalObject(_options_).
+ 1. Let _result_ be ? AddDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _sign_ × _other_.[[Years]], _sign_ × _other_.[[Months]], _sign_ × _other_.[[Weeks]], _sign_ × _other_.[[Days]], _sign_ × _other_.[[Hours]], _sign_ × _other_.[[Minutes]], _sign_ × _other_.[[Seconds]], _sign_ × _other_.[[Milliseconds]], _sign_ × _other_.[[Microseconds]], _sign_ × _other_.[[Nanoseconds]], _relativeTo_).
+ 1. Return ! CreateTemporalDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], _result_.[[Hours]], _result_.[[Minutes]], _result_.[[Seconds]], _result_.[[Milliseconds]], _result_.[[Microseconds]], _result_.[[Nanoseconds]]).
+
+
diff --git a/spec/instant.html b/spec/instant.html
index dae7c085ca..6917d85f57 100644
--- a/spec/instant.html
+++ b/spec/instant.html
@@ -226,9 +226,7 @@ Temporal.Instant.prototype.add ( _temporalDurationLike_ )
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
- 1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « *"years"*, *"months"*, *"weeks"*, *"days"* »).
- 1. Let _ns_ be ? AddInstant(_instant_.[[Nanoseconds]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]]).
- 1. Return ! CreateTemporalInstant(_ns_).
+ 1. Return ? AddDurationToOrSubtractDurationFromInstant(~add~, _instant_, _temporalDurationLike_).
@@ -241,9 +239,7 @@ Temporal.Instant.prototype.subtract ( _temporalDurationLike_ )
1. Let _instant_ be the *this* value.
1. Perform ? RequireInternalSlot(_instant_, [[InitializedTemporalInstant]]).
- 1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « *"years"*, *"months"*, *"weeks"*, *"days"* »).
- 1. Let _ns_ be ? AddInstant(_instant_.[[Nanoseconds]], -_duration_.[[Hours]], -_duration_.[[Minutes]], -_duration_.[[Seconds]], -_duration_.[[Milliseconds]], -_duration_.[[Microseconds]], -_duration_.[[Nanoseconds]]).
- 1. Return ! CreateTemporalInstant(_ns_).
+ 1. Return ? AddDurationToOrSubtractDurationFromInstant(~subtract~, _instant_, _temporalDurationLike_).
@@ -647,5 +643,24 @@ TemporalInstantToString ( _instant_, _timeZone_, _precision_ )
1. Return the string-concatenation of _dateTimeString_ and _timeZoneString_.
+
+
+ AddDurationToOrSubtractDurationFromInstant (
+ _operation_: ~add~ or ~subtract~,
+ _instant_: a Temporal.Instant,
+ _temporalDurationLike_: an ECMAScript language value,
+ ): either a normal completion containing a Temporal.Instant or an abrupt completion
+
+
+
+ 1. If _operation_ is ~subtract~, let _sign_ be -1. Otherwise, let _sign_ be 1.
+ 1. Let _duration_ be ? ToLimitedTemporalDuration(_temporalDurationLike_, « *"years"*, *"months"*, *"weeks"*, *"days"* »).
+ 1. Let _ns_ be ? AddInstant(_instant_.[[Nanoseconds]], _sign_ × _duration_.[[Hours]], _sign_ × _duration_.[[Minutes]], _sign_ × _duration_.[[Seconds]], _sign_ × _duration_.[[Milliseconds]], _sign_ × _duration_.[[Microseconds]], _sign_ × _duration_.[[Nanoseconds]]).
+ 1. Return ! CreateTemporalInstant(_ns_).
+
+
diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html
index 57b11113c0..32e8e935c3 100644
--- a/spec/plaindatetime.html
+++ b/spec/plaindatetime.html
@@ -452,12 +452,7 @@ Temporal.PlainDateTime.prototype.add ( _temporalDurationLike_ [ , _options_
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _result_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _dateTime_.[[Calendar]], _duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _options_).
- 1. Assert: IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.
- 1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
- 1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]]).
+ 1. Return ? AddDurationToOrSubtractDurationFromPlainDateTime(~add~, _dateTime_, _temporalDurationLike_, _options_).
@@ -470,12 +465,7 @@ Temporal.PlainDateTime.prototype.subtract ( _temporalDurationLike_ [ , _opti
1. Let _dateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_dateTime_, [[InitializedTemporalDateTime]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _result_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _dateTime_.[[Calendar]], -_duration_.[[Years]], -_duration_.[[Months]], -_duration_.[[Weeks]], -_duration_.[[Days]], -_duration_.[[Hours]], -_duration_.[[Minutes]], -_duration_.[[Seconds]], -_duration_.[[Milliseconds]], -_duration_.[[Microseconds]], -_duration_.[[Nanoseconds]], _options_).
- 1. Assert: IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.
- 1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
- 1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]]).
+ 1. Return ? AddDurationToOrSubtractDurationFromPlainDateTime(~subtract~, _dateTime_, _temporalDurationLike_, _options_).
@@ -1157,5 +1147,28 @@
1. Return ! CreateDurationRecord(_dateDifference_.[[Years]], _dateDifference_.[[Months]], _dateDifference_.[[Weeks]], _balanceResult_.[[Days]], _balanceResult_.[[Hours]], _balanceResult_.[[Minutes]], _balanceResult_.[[Seconds]], _balanceResult_.[[Milliseconds]], _balanceResult_.[[Microseconds]], _balanceResult_.[[Nanoseconds]]).
+
+
+ AddDurationToOrSubtractDurationFromPlainDateTime (
+ _operation_: ~add~ or ~subtract~,
+ _dateTime_: a Temporal.PlainDateTime,
+ _temporalDurationLike_: an ECMAScript language value,
+ _options_: an ECMAScript language value,
+ ): either a normal completion containing a Temporal.PlainDateTime or an abrupt completion
+
+
+
+ 1. If _operation_ is ~subtract~, let _sign_ be -1. Otherwise, let _sign_ be 1.
+ 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
+ 1. Set _options_ to ? GetOptionsObject(_options_).
+ 1. Let _result_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _dateTime_.[[Calendar]], _sign_ × _duration_.[[Years]], _sign_ × _duration_.[[Months]], _sign_ × _duration_.[[Weeks]], _sign_ × _duration_.[[Days]], _sign_ × _duration_.[[Hours]], _sign_ × _duration_.[[Minutes]], _sign_ × _duration_.[[Seconds]], _sign_ × _duration_.[[Milliseconds]], _sign_ × _duration_.[[Microseconds]], _sign_ × _duration_.[[Nanoseconds]], _options_).
+ 1. Assert: IsValidISODate(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]]) is *true*.
+ 1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
+ 1. Return ? CreateTemporalDateTime(_result_.[[Year]], _result_.[[Month]], _result_.[[Day]], _result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]], _dateTime_.[[Calendar]]).
+
+
diff --git a/spec/plaintime.html b/spec/plaintime.html
index 560edf0b94..8d7dcb5fd8 100644
--- a/spec/plaintime.html
+++ b/spec/plaintime.html
@@ -210,10 +210,7 @@ Temporal.PlainTime.prototype.add ( _temporalDurationLike_ )
1. Let _temporalTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_temporalTime_, [[InitializedTemporalTime]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Let _result_ be ! AddTime(_temporalTime_.[[ISOHour]], _temporalTime_.[[ISOMinute]], _temporalTime_.[[ISOSecond]], _temporalTime_.[[ISOMillisecond]], _temporalTime_.[[ISOMicrosecond]], _temporalTime_.[[ISONanosecond]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]]).
- 1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
- 1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
+ 1. Return ? AddDurationToOrSubtractDurationFromPlainTime(~add~, _temporalTime_, _temporalTime_).
@@ -226,10 +223,7 @@ Temporal.PlainTime.prototype.subtract ( _temporalDurationLike_ )
1. Let _temporalTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_temporalTime_, [[InitializedTemporalTime]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Let _result_ be ! AddTime(_temporalTime_.[[ISOHour]], _temporalTime_.[[ISOMinute]], _temporalTime_.[[ISOSecond]], _temporalTime_.[[ISOMillisecond]], _temporalTime_.[[ISOMicrosecond]], _temporalTime_.[[ISONanosecond]], -_duration_.[[Hours]], -_duration_.[[Minutes]], -_duration_.[[Seconds]], -_duration_.[[Milliseconds]], -_duration_.[[Microseconds]], -_duration_.[[Nanoseconds]]).
- 1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
- 1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
+ 1. Return ? AddDurationToOrSubtractDurationFromPlainTime(~subtract~, _temporalTime_, _temporalTime_).
@@ -963,5 +957,25 @@ RoundTime ( _hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanos
1. Return ! BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _result_).
+
+
+ AddDurationToOrSubtractDurationFromPlainTime (
+ _operation_: ~add~ or ~subtract~,
+ _temporalTime_: a Temporal.PlainTime,
+ _temporalDurationLike_: an ECMAScript language value,
+ ): either a normal completion containing a Temporal.PlainTime or an abrupt completion
+
+
+
+ 1. If _operation_ is ~subtract~, let _sign_ be -1. Otherwise, let _sign_ be 1.
+ 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
+ 1. Let _result_ be ! AddTime(_temporalTime_.[[ISOHour]], _temporalTime_.[[ISOMinute]], _temporalTime_.[[ISOSecond]], _temporalTime_.[[ISOMillisecond]], _temporalTime_.[[ISOMicrosecond]], _temporalTime_.[[ISONanosecond]], _sign_ × _duration_.[[Hours]], _sign_ × _duration_.[[Minutes]], _sign_ × _duration_.[[Seconds]], _sign_ × _duration_.[[Milliseconds]], _sign_ × _duration_.[[Microseconds]], _sign_ × _duration_.[[Nanoseconds]]).
+ 1. Assert: IsValidTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]) is *true*.
+ 1. Return ? CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]).
+
+
diff --git a/spec/plainyearmonth.html b/spec/plainyearmonth.html
index 4a3bcd7219..29411b8e0a 100644
--- a/spec/plainyearmonth.html
+++ b/spec/plainyearmonth.html
@@ -251,28 +251,7 @@ Temporal.PlainYearMonth.prototype.add ( _temporalDurationLike_ [ , _options_
1. Let _yearMonth_ be the *this* value.
1. Perform ? RequireInternalSlot(_yearMonth_, [[InitializedTemporalYearMonth]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Let _balanceResult_ be ? BalanceDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _calendar_ be _yearMonth_.[[Calendar]].
- 1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"monthCode"*, *"year"* »).
- 1. Let _fields_ be ? PrepareTemporalFields(_yearMonth_, _fieldNames_, «»).
- 1. Let _sign_ be ! DurationSign(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], 0, 0, 0, 0, 0, 0).
- 1. If _sign_ < 0, then
- 1. Let _dayFromCalendar_ be ? CalendarDaysInMonth(_calendar_, _yearMonth_).
- 1. Let _day_ be ? ToPositiveInteger(_dayFromCalendar_).
- 1. Else,
- 1. Let _day_ be 1.
- 1. Perform ! CreateDataPropertyOrThrow(_fields_, *"day"*, _day_).
- 1. Let _date_ be ? CalendarDateFromFields(_calendar_, _fields_, *undefined*).
- 1. Let _durationToAdd_ be ! CreateTemporalDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], 0, 0, 0, 0, 0, 0).
- 1. Let _optionsCopy_ be OrdinaryObjectCreate(%Object.prototype%).
- 1. Let _entries_ be ? EnumerableOwnPropertyNames(_options_, ~key+value~).
- 1. For each element _nextEntry_ of _entries_, do
- 1. Perform ! CreateDataPropertyOrThrow(_optionsCopy_, _nextEntry_[0], _nextEntry_[1]).
- 1. Let _addedDate_ be ? CalendarDateAdd(_calendar_, _date_, _durationToAdd_, _options_).
- 1. Let _addedDateFields_ be ? PrepareTemporalFields(_addedDate_, _fieldNames_, «»).
- 1. Return ? CalendarYearMonthFromFields(_calendar_, _addedDateFields_, _optionsCopy_).
+ 1. Return ? AddTemporalPlainYearMonth(~add~, _yearMonth_, _temporalDurationLike_, _options_).
@@ -285,29 +264,7 @@ Temporal.PlainYearMonth.prototype.subtract ( _temporalDurationLike_ [ , _opt
1. Let _yearMonth_ be the *this* value.
1. Perform ? RequireInternalSlot(_yearMonth_, [[InitializedTemporalYearMonth]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Set _duration_ to ! CreateNegatedTemporalDuration(_duration_).
- 1. Let _balanceResult_ be ? BalanceDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _calendar_ be _yearMonth_.[[Calendar]].
- 1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"monthCode"*, *"year"* »).
- 1. Let _fields_ be ? PrepareTemporalFields(_yearMonth_, _fieldNames_, «»).
- 1. Let _sign_ be ! DurationSign(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], 0, 0, 0, 0, 0, 0).
- 1. If _sign_ < 0, then
- 1. Let _dayFromCalendar_ be ? CalendarDaysInMonth(_calendar_, _yearMonth_).
- 1. Let _day_ be ? ToPositiveInteger(_dayFromCalendar_).
- 1. Else,
- 1. Let _day_ be 1.
- 1. Perform ! CreateDataPropertyOrThrow(_fields_, *"day"*, _day_).
- 1. Let _date_ be ? CalendarDateFromFields(_calendar_, _fields_, *undefined*).
- 1. Let _durationToAdd_ be ! CreateTemporalDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], 0, 0, 0, 0, 0, 0).
- 1. Let _optionsCopy_ be OrdinaryObjectCreate(%Object.prototype%).
- 1. Let _entries_ be ? EnumerableOwnPropertyNames(_options_, ~key+value~).
- 1. For each element _nextEntry_ of _entries_, do
- 1. Perform ! CreateDataPropertyOrThrow(_optionsCopy_, _nextEntry_[0], _nextEntry_[1]).
- 1. Let _addedDate_ be ? CalendarDateAdd(_calendar_, _date_, _durationToAdd_, _options_).
- 1. Let _addedDateFields_ be ? PrepareTemporalFields(_addedDate_, _fieldNames_, «»).
- 1. Return ? CalendarYearMonthFromFields(_calendar_, _addedDateFields_, _optionsCopy_).
+ 1. Return ? AddTemporalPlainYearMonth(~subtract~, _yearMonth_, _temporalDurationLike_, _options_).
@@ -697,5 +654,45 @@ TemporalYearMonthToString ( _yearMonth_, _showCalendar_ )
1. Return _result_.
+
+
+ AddTemporalPlainYearMonth (
+ _operation_: ~add~ or ~subtract_,
+ _yearMonth_: a Temporal.PlainYearMonth,
+ _temporalDurationLike_: an ECMAScript language value,
+ _options_: an ECMAScript language value,
+ ): either a normal completion containing a Temporal.PlainYearMonth or an abrupt completion
+
+
+
+ 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
+ 1. If _operation_ is ~subtract~, then
+ 1. Set _duration_ to ! CreateNegatedTemporalDuration(_duration_).
+ 1. Let _balanceResult_ be ? BalanceDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*).
+ 1. Set _options_ to ? GetOptionsObject(_options_).
+ 1. Let _calendar_ be _yearMonth_.[[Calendar]].
+ 1. Let _fieldNames_ be ? CalendarFields(_calendar_, « *"monthCode"*, *"year"* »).
+ 1. Let _fields_ be ? PrepareTemporalFields(_yearMonth_, _fieldNames_, «»).
+ 1. Set _sign_ to ! DurationSign(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], 0, 0, 0, 0, 0, 0).
+ 1. If _sign_ < 0, then
+ 1. Let _dayFromCalendar_ be ? CalendarDaysInMonth(_calendar_, _yearMonth_).
+ 1. Let _day_ be ? ToPositiveInteger(_dayFromCalendar_).
+ 1. Else,
+ 1. Let _day_ be 1.
+ 1. Perform ! CreateDataPropertyOrThrow(_fields_, *"day"*, _day_).
+ 1. Let _date_ be ? CalendarDateFromFields(_calendar_, _fields_, *undefined*).
+ 1. Let _durationToAdd_ be ! CreateTemporalDuration(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], 0, 0, 0, 0, 0, 0).
+ 1. Let _optionsCopy_ be OrdinaryObjectCreate(%Object.prototype%).
+ 1. Let _entries_ be ? EnumerableOwnPropertyNames(_options_, ~key+value~).
+ 1. For each element _nextEntry_ of _entries_, do
+ 1. Perform ! CreateDataPropertyOrThrow(_optionsCopy_, _nextEntry_[0], _nextEntry_[1]).
+ 1. Let _addedDate_ be ? CalendarDateAdd(_calendar_, _date_, _durationToAdd_, _options_).
+ 1. Let _addedDateFields_ be ? PrepareTemporalFields(_addedDate_, _fieldNames_, «»).
+ 1. Return ? CalendarYearMonthFromFields(_calendar_, _addedDateFields_, _optionsCopy_).
+
+
diff --git a/spec/zoneddatetime.html b/spec/zoneddatetime.html
index 3b80f12c59..89be6f835f 100644
--- a/spec/zoneddatetime.html
+++ b/spec/zoneddatetime.html
@@ -667,12 +667,7 @@ Temporal.ZonedDateTime.prototype.add ( _temporalDurationLike_ [ , _options_
1. Let _zonedDateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
- 1. Let _calendar_ be _zonedDateTime_.[[Calendar]].
- 1. Let _epochNanoseconds_ be ? AddZonedDateTime(_zonedDateTime_.[[Nanoseconds]], _timeZone_, _calendar_, _duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _options_).
- 1. Return ! CreateTemporalZonedDateTime(_epochNanoseconds_, _timeZone_, _calendar_).
+ 1. Return ? AddDurationToOrSubtractDurationFromZonedDateTime(~add~, _zonedDateTime_, _temporalDurationLike_, _options_).
@@ -685,12 +680,7 @@ Temporal.ZonedDateTime.prototype.subtract ( _temporalDurationLike_ [ , _opti
1. Let _zonedDateTime_ be the *this* value.
1. Perform ? RequireInternalSlot(_zonedDateTime_, [[InitializedTemporalZonedDateTime]]).
- 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
- 1. Set _options_ to ? GetOptionsObject(_options_).
- 1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
- 1. Let _calendar_ be _zonedDateTime_.[[Calendar]].
- 1. Let _epochNanoseconds_ be ? AddZonedDateTime(_zonedDateTime_.[[Nanoseconds]], _timeZone_, _calendar_, -_duration_.[[Years]], -_duration_.[[Months]], -_duration_.[[Weeks]], -_duration_.[[Days]], -_duration_.[[Hours]], -_duration_.[[Minutes]], -_duration_.[[Seconds]], -_duration_.[[Milliseconds]], -_duration_.[[Microseconds]], -_duration_.[[Nanoseconds]], _options_).
- 1. Return ! CreateTemporalZonedDateTime(_epochNanoseconds_, _timeZone_, _calendar_).
+ 1. Return ? AddDurationToOrSubtractDurationFromZonedDateTime(~subtract~, _zonedDateTime_, _temporalDurationLike_, _options_).
@@ -1399,5 +1389,28 @@
}.
+
+
+ AddDurationToOrSubtractDurationFromZonedDateTime (
+ _operation_: ~add~ or ~subtract~,
+ _zonedDateTime_: a Temporal.ZonedDateTime,
+ _temporalDurationLike_: an ECMAScript language value,
+ _options_: an ECMAScript language value,
+ ): either a normal completion containing a Temporal.ZonedDateTime or an abrupt completion
+
+
+
+ 1. If _operation_ is ~subtract~, let _sign_ be -1. Otherwise, let _sign_ be 1.
+ 1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_).
+ 1. Set _options_ to ? GetOptionsObject(_options_).
+ 1. Let _timeZone_ be _zonedDateTime_.[[TimeZone]].
+ 1. Let _calendar_ be _zonedDateTime_.[[Calendar]].
+ 1. Let _epochNanoseconds_ be ? AddZonedDateTime(_zonedDateTime_.[[Nanoseconds]], _timeZone_, _calendar_, _sign_ × _duration_.[[Years]], _sign_ × _duration_.[[Months]], _sign_ × _duration_.[[Weeks]], _sign_ × _duration_.[[Days]], _sign_ × _duration_.[[Hours]], _sign_ × _duration_.[[Minutes]], _sign_ × _duration_.[[Seconds]], _sign_ × _duration_.[[Milliseconds]], _sign_ × _duration_.[[Microseconds]], _sign_ × _duration_.[[Nanoseconds]], _options_).
+ 1. Return ! CreateTemporalZonedDateTime(_epochNanoseconds_, _timeZone_, _calendar_).
+
+