From 0c4792eb30a4e6d1c0845e5700d132401d07668e Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Fri, 10 Nov 2023 14:39:53 -0800 Subject: [PATCH] Post-adjustment: Make calendar method lookups unconditional This is to address a belated review comment from Richard on #2519. For each operation in which we need to observably look up calendar methods, make those lookups unconditional for every method that might be called. See: #2724 --- polyfill/lib/duration.mjs | 41 +------------- polyfill/lib/ecmascript.mjs | 107 +++++++----------------------------- polyfill/lib/plaindate.mjs | 15 +---- spec/duration.html | 34 ++---------- spec/plaindate.html | 19 ++----- spec/plaindatetime.html | 15 +---- spec/plainyearmonth.html | 15 +---- spec/zoneddatetime.html | 4 +- 8 files changed, 40 insertions(+), 210 deletions(-) diff --git a/polyfill/lib/duration.mjs b/polyfill/lib/duration.mjs index 1a50ad86d6..0c13520326 100644 --- a/polyfill/lib/duration.mjs +++ b/polyfill/lib/duration.mjs @@ -329,35 +329,7 @@ export class Duration { let calendarRec; if (zonedRelativeTo || plainRelativeTo) { const calendar = GetSlot(zonedRelativeTo ?? plainRelativeTo, CALENDAR); - calendarRec = new CalendarMethodRecord(calendar); - if ( - years !== 0 || - months !== 0 || - weeks !== 0 || - largestUnit === 'year' || - largestUnit === 'month' || - largestUnit === 'week' || - smallestUnit === 'year' || - smallestUnit === 'month' || - smallestUnit === 'week' - ) { - calendarRec.lookup('dateAdd'); - } - if ( - largestUnit === 'year' || - (largestUnit === 'month' && years !== 0) || - smallestUnit === 'year' || - // Edge condition in AdjustRoundedDurationDays: - (zonedRelativeTo && - !roundingGranularityIsNoop && - smallestUnit !== 'year' && - smallestUnit !== 'month' && - smallestUnit !== 'week' && - smallestUnit !== 'day' && - (largestUnit === 'year' || largestUnit === 'month' || largestUnit === 'week')) - ) { - calendarRec.lookup('dateUntil'); - } + calendarRec = new CalendarMethodRecord(calendar, ['dateAdd', 'dateUntil']); } ({ years, months, weeks, days } = ES.UnbalanceDateDurationRelative( @@ -500,13 +472,7 @@ export class Duration { calendar = GetSlot(plainRelativeTo, CALENDAR); } if (calendar) { - calendarRec = new CalendarMethodRecord(calendar); - if (years !== 0 || months !== 0 || weeks !== 0 || unit === 'year' || unit === 'month' || unit === 'week') { - calendarRec.lookup('dateAdd'); - } - if (unit === 'year' || (unit === 'month' && years !== 0)) { - calendarRec.lookup('dateUntil'); - } + calendarRec = new CalendarMethodRecord(calendar, ['dateAdd', 'dateUntil']); } // Convert larger units down to days @@ -760,8 +726,7 @@ export class Duration { let calendarRec; if (zonedRelativeTo || plainRelativeTo) { - calendarRec = new CalendarMethodRecord(GetSlot(zonedRelativeTo ?? plainRelativeTo, CALENDAR)); - if (calendarUnitsPresent) calendarRec.lookup('dateAdd'); + calendarRec = new CalendarMethodRecord(GetSlot(zonedRelativeTo ?? plainRelativeTo, CALENDAR), ['dateAdd']); } if (zonedRelativeTo && (calendarUnitsPresent || d1 != 0 || d2 !== 0)) { diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index ba90244f19..157f1a5808 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -4302,25 +4302,7 @@ export function DifferenceTemporalPlainDate(operation, plainDate, other, options return new Duration(); } - const calendarRec = new CalendarMethodRecord(calendar); - const roundingIsNoop = settings.smallestUnit === 'day' && settings.roundingIncrement === 1; - if ( - settings.smallestUnit === 'year' || - settings.smallestUnit === 'month' || - settings.smallestUnit === 'week' || - (!roundingIsNoop && - (settings.largestUnit === 'year' || settings.largestUnit === 'month' || settings.largestUnit === 'week')) - ) { - calendarRec.lookup('dateAdd'); - } - if ( - settings.largestUnit === 'year' || - settings.largestUnit === 'month' || - settings.largestUnit === 'week' || - settings.smallestUnit === 'year' - ) { - calendarRec.lookup('dateUntil'); - } + const calendarRec = new CalendarMethodRecord(calendar, ['dateAdd', 'dateUntil']); resolvedOptions.largestUnit = settings.largestUnit; const untilResult = DifferenceDate(calendarRec, plainDate, other, resolvedOptions); @@ -4329,6 +4311,7 @@ export function DifferenceTemporalPlainDate(operation, plainDate, other, options let weeks = GetSlot(untilResult, WEEKS); let days = GetSlot(untilResult, DAYS); + const roundingIsNoop = settings.smallestUnit === 'day' && settings.roundingIncrement === 1; if (!roundingIsNoop) { ({ years, months, weeks, days } = RoundDuration( years, @@ -4388,25 +4371,7 @@ export function DifferenceTemporalPlainDateTime(operation, plainDateTime, other, return new Duration(); } - const calendarRec = new CalendarMethodRecord(calendar); - const roundingIsNoop = settings.smallestUnit === 'nanosecond' && settings.roundingIncrement === 1; - if ( - settings.smallestUnit === 'year' || - settings.smallestUnit === 'month' || - settings.smallestUnit === 'week' || - (!datePartsIdentical && - !roundingIsNoop && - (settings.largestUnit === 'year' || settings.largestUnit === 'month' || settings.largestUnit === 'week')) - ) { - calendarRec.lookup('dateAdd'); - } - if ( - (!datePartsIdentical && - (settings.largestUnit === 'year' || settings.largestUnit === 'month' || settings.largestUnit === 'week')) || - settings.smallestUnit === 'year' - ) { - calendarRec.lookup('dateUntil'); - } + const calendarRec = new CalendarMethodRecord(calendar, ['dateAdd', 'dateUntil']); let { years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = DifferenceISODateTime( @@ -4433,6 +4398,7 @@ export function DifferenceTemporalPlainDateTime(operation, plainDateTime, other, resolvedOptions ); + const roundingIsNoop = settings.smallestUnit === 'nanosecond' && settings.roundingIncrement === 1; if (!roundingIsNoop) { const relativeTo = TemporalDateTimeToDate(plainDateTime); ({ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = RoundDuration( @@ -4570,13 +4536,7 @@ export function DifferenceTemporalPlainYearMonth(operation, yearMonth, other, op return new Duration(); } - const calendarRec = new CalendarMethodRecord(calendar); - if (settings.smallestUnit !== 'month' || settings.roundingIncrement !== 1) { - calendarRec.lookup('dateAdd'); - } - calendarRec.lookup('dateFromFields'); - calendarRec.lookup('dateUntil'); - calendarRec.lookup('fields'); + const calendarRec = new CalendarMethodRecord(calendar, ['dateAdd', 'dateFromFields', 'dateUntil', 'fields']); const fieldNames = CalendarFields(calendarRec, ['monthCode', 'year']); const thisFields = PrepareTemporalFields(yearMonth, fieldNames, []); @@ -4765,7 +4725,7 @@ export function AddISODate(year, month, day, years, months, weeks, days, overflo } export function AddDate(calendarRec, plainDate, duration, options = undefined) { - // dateAdd must be looked up if years, months, weeks != 0 + // dateAdd must be looked up const years = GetSlot(duration, YEARS); const months = GetSlot(duration, MONTHS); const weeks = GetSlot(duration, WEEKS); @@ -5174,31 +5134,10 @@ export function AddDurationToOrSubtractDurationFromDuration(operation, duration, let calendarRec; if (plainRelativeTo || zonedRelativeTo) { - calendarRec = new CalendarMethodRecord(GetSlot(zonedRelativeTo ?? plainRelativeTo, CALENDAR)); - if ( - GetSlot(duration, YEARS) !== 0 || - GetSlot(duration, MONTHS) !== 0 || - GetSlot(duration, WEEKS) !== 0 || - years !== 0 || - months !== 0 || - weeks !== 0 - ) { - calendarRec.lookup('dateAdd'); - if ( - years !== 0 || - months !== 0 || - weeks !== 0 || - days !== 0 || - hours !== 0 || - minutes !== 0 || - seconds !== 0 || - milliseconds !== 0 || - microseconds !== 0 || - nanoseconds !== 0 - ) { - calendarRec.lookup('dateUntil'); - } - } + calendarRec = new CalendarMethodRecord(GetSlot(zonedRelativeTo ?? plainRelativeTo, CALENDAR), [ + 'dateAdd', + 'dateUntil' + ]); } ({ years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = AddDuration( @@ -5258,10 +5197,7 @@ export function AddDurationToOrSubtractDurationFromPlainDateTime(operation, date ToTemporalDurationRecord(durationLike); options = GetOptionsObject(options); - const calendarRec = new CalendarMethodRecord(GetSlot(dateTime, CALENDAR)); - if (years !== 0 || months !== 0 || weeks !== 0) { - calendarRec.lookup('dateAdd'); - } + const calendarRec = new CalendarMethodRecord(GetSlot(dateTime, CALENDAR), ['dateAdd']); const { year, month, day, hour, minute, second, millisecond, microsecond, nanosecond } = AddDateTime( GetSlot(dateTime, ISO_YEAR), @@ -5350,14 +5286,14 @@ export function AddDurationToOrSubtractDurationFromPlainYearMonth(operation, yea ({ days } = BalanceTimeDuration(days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds, 'day')); const sign = DurationSign(years, months, weeks, days, 0, 0, 0, 0, 0, 0); - const calendarRec = new CalendarMethodRecord(GetSlot(yearMonth, CALENDAR)); - if (sign < 0 || years !== 0 || months !== 0 || weeks !== 0) { - calendarRec.lookup('dateAdd'); - } - calendarRec.lookup('dateFromFields'); - if (sign < 0) calendarRec.lookup('day'); - calendarRec.lookup('fields'); - calendarRec.lookup('yearMonthFromFields'); + const calendarRec = new CalendarMethodRecord(GetSlot(yearMonth, CALENDAR), [ + 'dateAdd', + 'dateFromFields', + 'day', + 'fields', + 'yearMonthFromFields' + ]); + const fieldNames = CalendarFields(calendarRec, ['monthCode', 'year']); const fields = PrepareTemporalFields(yearMonth, fieldNames, []); const fieldsCopy = SnapshotOwnProperties(fields, null); @@ -5404,10 +5340,7 @@ export function AddDurationToOrSubtractDurationFromZonedDateTime(operation, zone 'getOffsetNanosecondsFor', 'getPossibleInstantsFor' ]); - const calendarRec = new CalendarMethodRecord(GetSlot(zonedDateTime, CALENDAR)); - if (years !== 0 || months !== 0 || weeks !== 0) { - calendarRec.lookup('dateAdd'); - } + const calendarRec = new CalendarMethodRecord(GetSlot(zonedDateTime, CALENDAR), ['dateAdd']); const epochNanoseconds = AddZonedDateTime( GetSlot(zonedDateTime, INSTANT), timeZoneRec, diff --git a/polyfill/lib/plaindate.mjs b/polyfill/lib/plaindate.mjs index 06d4b695a7..b74236ef1c 100644 --- a/polyfill/lib/plaindate.mjs +++ b/polyfill/lib/plaindate.mjs @@ -14,9 +14,6 @@ import { ISO_NANOSECOND, CALENDAR, EPOCHNANOSECONDS, - MONTHS, - WEEKS, - YEARS, GetSlot } from './slots.mjs'; @@ -122,11 +119,7 @@ export class PlainDate { const duration = ES.ToTemporalDuration(temporalDurationLike); options = ES.GetOptionsObject(options); - const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR)); - if (GetSlot(duration, YEARS) !== 0 || GetSlot(duration, MONTHS) !== 0 || GetSlot(duration, WEEKS) !== 0) { - calendarRec.lookup('dateAdd'); - } - + const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR), ['dateAdd']); return ES.AddDate(calendarRec, this, duration, options); } subtract(temporalDurationLike, options = undefined) { @@ -135,11 +128,7 @@ export class PlainDate { const duration = ES.CreateNegatedTemporalDuration(ES.ToTemporalDuration(temporalDurationLike)); options = ES.GetOptionsObject(options); - const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR)); - if (GetSlot(duration, YEARS) !== 0 || GetSlot(duration, MONTHS) !== 0 || GetSlot(duration, WEEKS) !== 0) { - calendarRec.lookup('dateAdd'); - } - + const calendarRec = new CalendarMethodRecord(GetSlot(this, CALENDAR), ['dateAdd']); return ES.AddDate(calendarRec, this, duration, options); } until(other, options = undefined) { diff --git a/spec/duration.html b/spec/duration.html index 6969f9a49e..063316676a 100644 --- a/spec/duration.html +++ b/spec/duration.html @@ -105,9 +105,7 @@

Temporal.Duration.compare ( _one_, _two_ [ , _options_ ] )

1. Let _calendarRec_ be *undefined*. 1. If _zonedRelativeTo_ is not *undefined* or _plainRelativeTo_ is not *undefined*, then 1. If _zonedRelativeTo_ is not *undefined*, let _calendar_ be _zonedRelativeTo_.[[Calendar]]; else let _calendar_ be _plainRelativeTo_.[[Calendar]]. - 1. Set _calendarRec_ to ! CreateCalendarMethodsRecord(_calendar_, « »). - 1. If _calendarUnitsPresent_ is *true*, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). + 1. Set _calendarRec_ to ? CreateCalendarMethodsRecord(_calendar_, « ~dateAdd~ »). 1. If _zonedRelativeTo_ is not *undefined*, and either _calendarUnitsPresent_ is *true*, or _one_.[[Days]] ≠ 0, or _two_.[[Days]] ≠ 0, then 1. Let _instant_ be ! CreateTemporalInstant(_zonedRelativeTo_.[[Nanoseconds]]). 1. Let _precalculatedPlainDateTime_ be ? GetPlainDateTimeFor(_timeZoneRec_, _instant_, _calendarRec_.[[Receiver]]). @@ -475,23 +473,7 @@

Temporal.Duration.prototype.round ( _roundTo_ )

1. Let _calendarRec_ be *undefined*. 1. If _zonedRelativeTo_ is not *undefined* or _plainRelativeTo_ is not *undefined*, then 1. If _zonedRelativeTo_ is not *undefined*, let _calendar_ be _zonedRelativeTo_.[[Calendar]]; else let _calendar_ be _plainRelativeTo_.[[Calendar]]. - 1. Set _calendarRec_ to ! CreateCalendarMethodsRecord(_calendar_, « »). - 1. If _largestUnit_ is *"year"*, or _largestUnit_ is *"month"*, or _largestUnit_ is *"week"*, let _largestUnitIsCalendarUnit_ be *true*; else let _largestUnitIsCalendarUnit_ be *false*. - 1. If _smallestUnit_ is *"year"*, or _smallestUnit_ is *"month"*, or _smallestUnit_ is *"week"*, let _smallestUnitIsCalendarUnit_ be *true*; else let _smallestUnitIsCalendarUnit_ be *false*. - 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, or _largestUnitIsCalendarUnit_ is *true*, or _smallestUnitIsCalendarUnit_ is *true*; then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). - 1. Let _dateUntilMayBeCalled_ be *false*. - 1. If _largestUnit_ is *"year"*, set _dateUntilMayBeCalled_ to *true*. - 1. If _largestUnit_ is *"month"* and _duration_.[[Years]] ≠ 0, set _dateUntilMayBeCalled_ to *true*. - 1. If _smallestUnit_ is *"year"*, set _dateUntilMayBeCalled_ to *true*. - 1. Let _dateUntilMayBeCalledInAdjustDurationEdgeCase_ be *true*. - 1. If _zonedRelativeTo_ is *undefined*, set _dateUntilMayBeCalledInAdjustDurationEdgeCase_ to *false*. - 1. If _roundingGranularityIsNoop_ is *true*, set _dateUntilMayBeCalledInAdjustDurationEdgeCase_ to *false*. - 1. If _smallestUnitIsCalendarUnit_ is *true*, set _dateUntilMayBeCalledInAdjustDurationEdgeCase_ to *false*. - 1. If _largestUnitIsCalendarUnit_ is *false*, set _dateUntilMayBeCalledInAdjustDurationEdgeCase_ to *false*. - 1. If _dateUntilMayBeCalledInAdjustDurationEdgeCase_ is *true*, set _dateUntilMayBeCalled_ to *true*. - 1. If _dateUntilMayBeCalled_ is *true*, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateUntil~). + 1. Set _calendarRec_ to ? CreateCalendarMethodsRecord(_calendar_, « ~dateAdd~, ~dateUntil~ »). 1. Let _unbalanceResult_ be ? UnbalanceDateDurationRelative(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _largestUnit_, _plainRelativeTo_, _calendarRec_). 1. Let _roundRecord_ be ? RoundDuration(_unbalanceResult_.[[Years]], _unbalanceResult_.[[Months]], _unbalanceResult_.[[Weeks]], _unbalanceResult_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], _roundingIncrement_, _smallestUnit_, _roundingMode_, _plainRelativeTo_, _calendarRec_, _zonedRelativeTo_, _timeZoneRec_, _precalculatedPlainDateTime_). 1. Let _roundResult_ be _roundRecord_.[[DurationRecord]]. @@ -536,11 +518,7 @@

Temporal.Duration.prototype.total ( _totalOf_ )

1. Let _calendarRec_ be *undefined*. 1. If _zonedRelativeTo_ is not *undefined* and _plainRelativeTo_ is not *undefined*, then 1. If _zonedRelativeTo_ is not *undefined*, let _calendar_ be _zonedRelativeTo_.[[Calendar]]; else let _calendar_ be _plainRelativeTo_.[[Calendar]]. - 1. Set _calendarRec_ to ! CreateCalendarMethodsRecord(_calendar_, « »). - 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, or _unit_ is *"year"*, or _unit_ is *"month"*, or _unit_ is *"week"*, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). - 1. If _unit_ is *"year"*, or _unit_ is *"month"* and _duration_.[[Years]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateUntil~). + 1. Set _calendarRec_ to ? CreateCalendarMethodsRecord(_calendar_, « ~dateAdd~, ~dateUntil~ »). 1. Let _unbalanceResult_ be ? UnbalanceDateDurationRelative(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _duration_.[[Days]], _unit_, _plainRelativeTo_, _calendarRec_). 1. If _zonedRelativeTo_ is not *undefined*, then 1. Let _intermediate_ be ? MoveRelativeZonedDateTime(_zonedRelativeTo_, _calendarRec_, _timeZoneRec_, _unbalanceResult_.[[Years]], _unbalanceResult_.[[Months]], _unbalanceResult_.[[Weeks]], 0, _precalculatedPlainDateTime_). @@ -2030,11 +2008,7 @@

1. Let _calendarRec_ be *undefined*. 1. If _zonedRelativeTo_ is not *undefined* and _plainRelativeTo_ is not *undefined*, then 1. If _zonedRelativeTo_ is not *undefined*, let _calendar_ be _zonedRelativeTo_.[[Calendar]]; else let _calendar_ be _plainRelativeTo_.[[Calendar]]. - 1. Set _calendarRec_ to ! CreateCalendarMethodsRecord(_calendar_, « »). - 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, or _other_.[[Years]] ≠ 0, or _other_.[[Months]] ≠ 0, or _other_.[[Weeks]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). - 1. If _other_.[[Years]] ≠ 0, or _other_.[[Months]] ≠ 0, or _other_.[[Weeks]] ≠ 0, or _other_.[[Days]] ≠ 0, or _other_.[[Hours]] ≠ 0, or _other_.[[Minutes]] ≠ 0, or _other_.[[Seconds]] ≠ 0, or _other_.[[Milliseconds]] ≠ 0, or _other_.[[Microseconds]] ≠ 0, or _other_.[[Nanoseconds]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateUntil~). + 1. Set _calendarRec_ to ? CreateCalendarMethodsRecord(_calendar_, « ~dateAdd~, ~dateUntil~ »). 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]], _plainRelativeTo_, _calendarRec_, _zonedRelativeTo_, _timeZoneRec_). 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/plaindate.html b/spec/plaindate.html index e50985efef..4cae182b21 100644 --- a/spec/plaindate.html +++ b/spec/plaindate.html @@ -377,9 +377,7 @@

Temporal.PlainDate.prototype.add ( _temporalDurationLike_ [ , _options_ ] )< 1. Perform ? RequireInternalSlot(_temporalDate_, [[InitializedTemporalDate]]). 1. Let _duration_ be ? ToTemporalDuration(_temporalDurationLike_). 1. Set _options_ to ? GetOptionsObject(_options_). - 1. Let _calendarRec_ be ! CreateCalendarMethodsRecord(_temporalDate_.[[Calendar]], « »). - 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_temporalDate_.[[Calendar]], « ~dateAdd~ »). 1. Return ? AddDate(_calendarRec_, _temporalDate_, _duration_, _options_). @@ -395,9 +393,7 @@

Temporal.PlainDate.prototype.subtract ( _temporalDurationLike_ [ , _options_ 1. Let _duration_ be ? ToTemporalDuration(_temporalDurationLike_). 1. Set _options_ to ? GetOptionsObject(_options_). 1. Let _negatedDuration_ be ! CreateNegatedTemporalDuration(_duration_). - 1. Let _calendarRec_ be ! CreateCalendarMethodsRecord(_temporalDate_.[[Calendar]], « »). - 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_temporalDate_.[[Calendar]], « ~dateAdd~ »). 1. Return ? AddDate(_calendarRec_, _temporalDate_, _negatedDuration_, _options_). @@ -1010,6 +1006,7 @@

+ 1. Assert: CalendarMethodsRecordHasLookedUp(_calendarRec_, ~dateAdd~) is *true*. 1. If _options_ is not present, set _options_ to *undefined*. 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, then 1. Return ? CalendarDateAdd(_calendarRec_, _plainDate_, _duration_, _options_). @@ -1054,16 +1051,10 @@

1. Let _settings_ be ? GetDifferenceSettings(_operation_, _resolvedOptions_, ~date~, « », *"day"*, *"day"*). 1. If _temporalDate_.[[ISOYear]] = _other_.[[ISOYear]], and _temporalDate_.[[ISOMonth]] = _other_.[[ISOMonth]], and _temporalDate_.[[ISODay]] = _other_.[[ISODay]], then 1. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0). - 1. Let _calendarRec_ be ! CreateCalendarMethodsRecord(_temporalDate_.[[Calendar]], « »). - 1. If _settings_.[[SmallestUnit]] is *"day"* and _settings_.[[RoundingIncrement]] = 1, let _roundingGranularityIsNoop_ be *true*; else let _roundingGranularityIsNoop_ be *false*. - 1. If _settings_.[[LargestUnit]] is *"year"*, or _settings_.[[LargestUnit]] is *"month"*, or _settings_.[[LargestUnit]] is *"week"*, let _largestUnitIsCalendarUnit_ be *true*; else let _largestUnitIsCalendarUnit_ be *false*. - 1. If _roundingGranularityIsNoop_ is *false* and _largestUnitIsCalendarUnit_ is *true*, let _roundingRequiresDateAddLookup_ be *true*; else let _roundingRequiresDateAddLookup_ be *false*. - 1. If _settings_.[[SmallestUnit]] is *"year"*, or _settings_.[[SmallestUnit]] is *"month"*, or _settings_.[[SmallestUnit]] is *"week"*, or _roundingRequiresDateAddLookup_ is *true*, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). - 1. If _largestUnitIsCalendarUnit_ is *true*, or _settings_.[[SmallestUnit]] is *"year"*, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateUntil~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_temporalDate_.[[Calendar]], « ~dateAdd~, ~dateUntil~ »). 1. Perform ! CreateDataPropertyOrThrow(_resolvedOptions_, *"largestUnit"*, _settings_.[[LargestUnit]]). 1. Let _result_ be ? DifferenceDate(_calendarRec_, _temporalDate_, _other_, _resolvedOptions_). + 1. If _settings_.[[SmallestUnit]] is *"day"* and _settings_.[[RoundingIncrement]] = 1, let _roundingGranularityIsNoop_ be *true*; else let _roundingGranularityIsNoop_ be *false*. 1. If _roundingGranularityIsNoop_ is *false*, then 1. Let _roundRecord_ be ? RoundDuration(_result_.[[Years]], _result_.[[Months]], _result_.[[Weeks]], _result_.[[Days]], 0, 0, 0, 0, 0, 0, _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]], _temporalDate_, _calendarRec_). 1. Let _roundResult_ be _roundRecord_.[[DurationRecord]]. diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html index 1640bd71f1..7ba4193b07 100644 --- a/spec/plaindatetime.html +++ b/spec/plaindatetime.html @@ -1303,16 +1303,9 @@

1. Set _datePartsIdentical_ to *true*. 1. If _datePartsIdentical_ is *true*, and _dateTime_.[[ISOHour]] = _other_.[[ISOHour]], and _dateTime_.[[ISOMinute]] = _other_.[[ISOMinute]], and _dateTime_.[[ISOSecond]] = _other_.[[ISOSecond]], and _dateTime_.[[ISOMillisecond]] = _other_.[[ISOMillisecond]], and _dateTime_.[[ISOMicrosecond]] = _other_.[[ISOMicrosecond]], and _dateTime_.[[ISONanosecond]] = _other_.[[ISONanosecond]], then 1. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0). - 1. Let _calendarRec_ be ! CreateCalendarMethodsRecord(_dateTime_.[[Calendar]], « »). - 1. If _settings_.[[SmallestUnit]] is *"nanosecond"* and _settings_.[[RoundingIncrement]] = 1, let _roundingGranularityIsNoop_ be *true*; else let _roundingGranularityIsNoop_ be *false*. - 1. If _settings_.[[LargestUnit]] is *"year"*, or _settings_.[[LargestUnit]] is *"month"*, or _settings_.[[LargestUnit]] is *"week"*, let _largestUnitIsCalendarUnit_ be *true*; else let _largestUnitIsCalendarUnit_ be *false*. - 1. If _roundingGranularityIsNoop_ is *false* and _largestUnitIsCalendarUnit_ is *true*, let _roundingRequiresDateAddLookup_ be *true*; else let _roundingRequiresDateAddLookup_ be *false*. - 1. If _settings_.[[SmallestUnit]] is *"year"*, or _settings_.[[SmallestUnit]] is *"month"*, or _settings_.[[SmallestUnit]] is *"week"*, or _roundingRequiresDateAddLookup_ is *true*, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). - 1. If _datePartsIdentical_ is *false* and _largestUnitIsCalendarUnit_ is *true*, let _largestUnitRequiresDateUntilLookup_ be *true*; else let _largestUnitRequiresDateUntilLookup_ be *false*. - 1. If _largestUnitRequiresDateUntilLookup_ is *true*, or _settings_.[[SmallestUnit]] is *"year"*, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateUntil~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_dateTime_.[[Calendar]], « ~dateAdd~, ~dateUntil~ »). 1. Let _diff_ be ? DifferenceISODateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _other_.[[ISOYear]], _other_.[[ISOMonth]], _other_.[[ISODay]], _other_.[[ISOHour]], _other_.[[ISOMinute]], _other_.[[ISOSecond]], _other_.[[ISOMillisecond]], _other_.[[ISOMicrosecond]], _other_.[[ISONanosecond]], _calendarRec_, _settings_.[[LargestUnit]], _resolvedOptions_). + 1. If _settings_.[[SmallestUnit]] is *"nanosecond"* and _settings_.[[RoundingIncrement]] = 1, let _roundingGranularityIsNoop_ be *true*; else let _roundingGranularityIsNoop_ be *false*. 1. If _roundingGranularityIsNoop_ is *true*, then 1. Return ! CreateTemporalDuration(_sign_ × _diff_.[[Years]], _sign_ × _diff_.[[Months]], _sign_ × _diff_.[[Weeks]], _sign_ × _diff_.[[Days]], _sign_ × _diff_.[[Hours]], _sign_ × _diff_.[[Minutes]], _sign_ × _diff_.[[Seconds]], _sign_ × _diff_.[[Milliseconds]], _sign_ × _diff_.[[Microseconds]], _sign_ × _diff_.[[Nanoseconds]]). 1. Let _relativeTo_ be ! CreateTemporalDate(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[Calendar]]). @@ -1340,9 +1333,7 @@

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 _calendarRec_ be ! CreateCalendarMethodsRecord(_dateTime_.[[Calendar]], « »). - 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_dateTime_.[[Calendar]], « ~dateAdd~ »). 1. Let _result_ be ? AddDateTime(_dateTime_.[[ISOYear]], _dateTime_.[[ISOMonth]], _dateTime_.[[ISODay]], _dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _calendarRec_, _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*. diff --git a/spec/plainyearmonth.html b/spec/plainyearmonth.html index 25b98f5f21..e4037227bf 100644 --- a/spec/plainyearmonth.html +++ b/spec/plainyearmonth.html @@ -641,12 +641,7 @@

1. If _yearMonth_.[[ISOYear]] = _other_.[[ISOYear]] and _yearMonth_.[[ISOMonth]] = _other_.[[ISOMonth]] and _yearMonth_.[[ISODay]] = _other_.[[ISODay]], then 1. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0). 1. Perform ! CreateDataPropertyOrThrow(_resolvedOptions_, *"largestUnit"*, _settings_.[[LargestUnit]]). - 1. Let _calendarRec_ be ! CreateCalendarMethodsRecord(_calendar_, « »). - 1. If _settings_.[[SmallestUnit]] is not *"month"* or _settings_.[[RoundingIncrement]] ≠ 1, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateFromFields~). - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateUntil~). - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~fields~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_calendar_, « ~dateAdd~, ~dateFromFields~, ~dateUntil~, ~fields~ »). 1. Let _fieldNames_ be ? CalendarFields(_calendarRec_, « *"monthCode"*, *"year"* »). 1. Let _thisFields_ be ? PrepareTemporalFields(_yearMonth_, _fieldNames_, «»). 1. Perform ! CreateDataPropertyOrThrow(_thisFields_, *"day"*, *1*𝔽). @@ -682,13 +677,7 @@

1. Set _duration_ to ! CreateNegatedTemporalDuration(_duration_). 1. Let _balanceResult_ be ? BalanceTimeDuration(_duration_.[[Days]], _duration_.[[Hours]], _duration_.[[Minutes]], _duration_.[[Seconds]], _duration_.[[Milliseconds]], _duration_.[[Microseconds]], _duration_.[[Nanoseconds]], *"day"*). 1. Let _sign_ be ! DurationSign(_duration_.[[Years]], _duration_.[[Months]], _duration_.[[Weeks]], _balanceResult_.[[Days]], 0, 0, 0, 0, 0, 0). - 1. Let _calendarRec_ be ! CreateCalendarMethodsRecord(_yearMonth_.[[Calendar]], « »). - 1. If _sign_ < 0, or _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateFromFields~). - 1. If _sign_ < 0, perform ? CalendarMethodsRecordLookup(_calendarRec_, ~day~). - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~fields~). - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~yearMonthFromFields~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_yearMonth_.[[Calendar]], « ~dateAdd~, ~dateFromFields~, ~day~, ~fields~, ~yearMonthFromFields~ »). 1. Let _fieldNames_ be ? CalendarFields(_calendarRec_, « *"monthCode"*, *"year"* »). 1. Let _fields_ be ? PrepareTemporalFields(_yearMonth_, _fieldNames_, «»). 1. Let _fieldsCopy_ be ! SnapshotOwnProperties(_fields_, *null*). diff --git a/spec/zoneddatetime.html b/spec/zoneddatetime.html index 6c34f13310..722ec816e2 100644 --- a/spec/zoneddatetime.html +++ b/spec/zoneddatetime.html @@ -1543,9 +1543,7 @@

1. Let _duration_ be ? ToTemporalDurationRecord(_temporalDurationLike_). 1. Set _options_ to ? GetOptionsObject(_options_). 1. Let _timeZoneRec_ be ? CreateTimeZoneMethodsRecord(_zonedDateTime_.[[TimeZone]], « ~getOffsetNanosecondsFor~, ~getPossibleInstantsFor~ »). - 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_zonedDateTime_.[[Calendar]], « »). - 1. If _duration_.[[Years]] ≠ 0, or _duration_.[[Months]] ≠ 0, or _duration_.[[Weeks]] ≠ 0, then - 1. Perform ? CalendarMethodsRecordLookup(_calendarRec_, ~dateAdd~). + 1. Let _calendarRec_ be ? CreateCalendarMethodsRecord(_zonedDateTime_.[[Calendar]], « ~dateAdd~ »). 1. Let _epochNanoseconds_ be ? AddZonedDateTime(_zonedDateTime_.[[Nanoseconds]], _timeZoneRec_, _calendarRec_, _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]], *undefined*, _options_). 1. Return ! CreateTemporalZonedDateTime(_epochNanoseconds_, _timeZoneRec_.[[Receiver]], _calendarRec_.[[Receiver]]).