diff --git a/polyfill/lib/duration.mjs b/polyfill/lib/duration.mjs index bd578d695..e8834e322 100644 --- a/polyfill/lib/duration.mjs +++ b/polyfill/lib/duration.mjs @@ -251,7 +251,10 @@ export class Duration { if (plainRelativeTo) { let duration = ES.NormalizeDurationWith24HourDays(this); - const targetTime = ES.AddTime(0, 0, 0, 0, 0, 0, duration.norm); + const targetTime = ES.AddTime( + { hour: 0, minute: 0, second: 0, millisecond: 0, microsecond: 0, nanosecond: 0 }, + duration.norm + ); // Delegate the date part addition to the calendar const isoRelativeToDate = ES.TemporalObjectToISODateRecord(plainRelativeTo); @@ -324,7 +327,10 @@ export class Duration { if (plainRelativeTo) { const duration = ES.NormalizeDurationWith24HourDays(this); - let targetTime = ES.AddTime(0, 0, 0, 0, 0, 0, duration.norm); + let targetTime = ES.AddTime( + { hour: 0, minute: 0, second: 0, millisecond: 0, microsecond: 0, nanosecond: 0 }, + duration.norm + ); // Delegate the date part addition to the calendar const isoRelativeToDate = ES.TemporalObjectToISODateRecord(plainRelativeTo); diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index d4b740402..35ca321cd 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -2053,7 +2053,7 @@ export function DisambiguatePossibleEpochNanoseconds(possibleEpochNs, timeZone, switch (disambiguation) { case 'earlier': { const norm = TimeDuration.normalize(0, 0, 0, 0, 0, -nanoseconds); - const earlierTime = AddTime(hour, minute, second, millisecond, microsecond, nanosecond, norm); + const earlierTime = AddTime(isoDateTime, norm); const earlierDate = BalanceISODate(year, month, day + earlierTime.deltaDays); return GetPossibleEpochNanoseconds(timeZone, { ...earlierTime, ...earlierDate })[0]; } @@ -2061,7 +2061,7 @@ export function DisambiguatePossibleEpochNanoseconds(possibleEpochNs, timeZone, // fall through because 'compatible' means 'later' for "spring forward" transitions case 'later': { const norm = TimeDuration.normalize(0, 0, 0, 0, 0, nanoseconds); - const laterTime = AddTime(hour, minute, second, millisecond, microsecond, nanosecond, norm); + const laterTime = AddTime(isoDateTime, norm); const laterDate = BalanceISODate(year, month, day + laterTime.deltaDays); const possible = GetPossibleEpochNanoseconds(timeZone, { ...laterTime, ...laterDate }); return possible[possible.length - 1]; @@ -4208,7 +4208,7 @@ export function DifferenceTemporalZonedDateTime(operation, zonedDateTime, other, return result; } -export function AddTime(hour, minute, second, millisecond, microsecond, nanosecond, norm) { +export function AddTime({ hour, minute, second, millisecond, microsecond, nanosecond }, norm) { second += norm.sec; nanosecond += norm.subsec; return BalanceTime(hour, minute, second, millisecond, microsecond, nanosecond); @@ -4305,12 +4305,14 @@ export function AddDurationToDateTime(operation, dateTime, durationLike, options // Add the time part const timeResult = AddTime( - GetSlot(dateTime, ISO_HOUR), - GetSlot(dateTime, ISO_MINUTE), - GetSlot(dateTime, ISO_SECOND), - GetSlot(dateTime, ISO_MILLISECOND), - GetSlot(dateTime, ISO_MICROSECOND), - GetSlot(dateTime, ISO_NANOSECOND), + { + hour: GetSlot(dateTime, ISO_HOUR), + minute: GetSlot(dateTime, ISO_MINUTE), + second: GetSlot(dateTime, ISO_SECOND), + millisecond: GetSlot(dateTime, ISO_MILLISECOND), + microsecond: GetSlot(dateTime, ISO_MICROSECOND), + nanosecond: GetSlot(dateTime, ISO_NANOSECOND) + }, normalizedDuration.norm ); const dateDuration = AdjustDateDurationRecord(normalizedDuration.date, timeResult.deltaDays); @@ -4345,12 +4347,14 @@ export function AddDurationToTime(operation, temporalTime, durationLike) { if (operation === 'subtract') duration = CreateNegatedTemporalDuration(duration); const normalizedDuration = NormalizeDurationWith24HourDays(duration); let { hour, minute, second, millisecond, microsecond, nanosecond } = AddTime( - GetSlot(temporalTime, ISO_HOUR), - GetSlot(temporalTime, ISO_MINUTE), - GetSlot(temporalTime, ISO_SECOND), - GetSlot(temporalTime, ISO_MILLISECOND), - GetSlot(temporalTime, ISO_MICROSECOND), - GetSlot(temporalTime, ISO_NANOSECOND), + { + hour: GetSlot(temporalTime, ISO_HOUR), + minute: GetSlot(temporalTime, ISO_MINUTE), + second: GetSlot(temporalTime, ISO_SECOND), + millisecond: GetSlot(temporalTime, ISO_MILLISECOND), + microsecond: GetSlot(temporalTime, ISO_MICROSECOND), + nanosecond: GetSlot(temporalTime, ISO_NANOSECOND) + }, normalizedDuration.norm ); ({ hour, minute, second, millisecond, microsecond, nanosecond } = RegulateTime( diff --git a/spec/duration.html b/spec/duration.html index 1e4d8d961..eb0768673 100644 --- a/spec/duration.html +++ b/spec/duration.html @@ -437,7 +437,8 @@

Temporal.Duration.prototype.round ( _roundTo_ )

1. Return ? UnnormalizeDuration(_normalizedDuration_, _largestUnit_). 1. If _plainRelativeTo_ is not *undefined*, then 1. Let _normalizedDuration_ be NormalizeDurationWith24HourDays(_duration_). - 1. Let _targetTime_ be AddTime(0, 0, 0, 0, 0, 0, _normalizedDuration_.[[NormalizedTime]]). + 1. Let _midnight_ be Time Record { [[Hour]]: 0, [[Minute]]: 0, [[Second]]: 0, [[Millisecond]]: 0, [[Microsecond]]: 0, [[Nanosecond]]: 0 }. + 1. Let _targetTime_ be AddTime(_midnight_, _normalizedDuration_.[[NormalizedTime]]). 1. Let _isoRelativeToDate_ be TemporalObjectToISODateRecord(_plainRelativeTo_). 1. Let _calendar_ be _plainRelativeTo_.[[Calendar]]. 1. Let _dateDuration_ be ! AdjustDateDurationRecord(_normalizedDuration_.[[Date]], _targetTime_.[[Days]]). @@ -479,7 +480,8 @@

Temporal.Duration.prototype.total ( _totalOf_ )

1. Let _total_ be ? DifferenceZonedDateTimeWithTotal(_relativeEpochNs_, _targetEpochNs_, _timeZone_, _calendar_, _unit_). 1. Else if _plainRelativeTo_ is not *undefined*, then 1. Let _normalizedDuration_ be NormalizeDurationWith24HourDays(_duration_). - 1. Let _targetTime_ be AddTime(0, 0, 0, 0, 0, 0, _normalizedDuration_.[[NormalizedTime]]). + 1. Let _midnight_ be Time Record { [[Hour]]: 0, [[Minute]]: 0, [[Second]]: 0, [[Millisecond]]: 0, [[Microsecond]]: 0, [[Nanosecond]]: 0 }. + 1. Let _targetTime_ be AddTime(_midnight_, _normalizedDuration_.[[NormalizedTime]]). 1. Let _isoRelativeToDate_ be TemporalObjectToISODateRecord(_plainRelativeTo_). 1. Let _calendar_ be _plainRelativeTo_.[[Calendar]]. 1. Let _dateDuration_ be ! AdjustDateDurationRecord(_normalizedDuration_.[[Date]], _targetTime_.[[Days]]). diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html index 9cdc5f2bc..08dcf7b05 100644 --- a/spec/plaindatetime.html +++ b/spec/plaindatetime.html @@ -1306,7 +1306,8 @@

1. Let _resolvedOptions_ be ? GetOptionsObject(_options_). 1. Let _overflow_ be ? GetTemporalOverflowOption(_resolvedOptions_). 1. Let _normalizedDuration_ be NormalizeDurationWith24HourDays(_duration_). - 1. Let _timeResult_ be AddTime(_dateTime_.[[ISOHour]], _dateTime_.[[ISOMinute]], _dateTime_.[[ISOSecond]], _dateTime_.[[ISOMillisecond]], _dateTime_.[[ISOMicrosecond]], _dateTime_.[[ISONanosecond]], _normalizedDuration_.[[NormalizedTime]]). + 1. Let _time_ be Time Record { [[Hour]]: _dateTime_.[[ISOHour]], [[Minute]]: _dateTime_.[[ISOMinute]], [[Second]]: _dateTime_.[[ISOSecond]], [[Millisecond]]: _dateTime_.[[ISOMillisecond]], [[Microsecond]]: _dateTime_.[[ISOMicrosecond]], [[Nanosecond]]: _dateTime_.[[ISONanosecond]] }. + 1. Let _timeResult_ be AddTime(_time_, _normalizedDuration_.[[NormalizedTime]]). 1. Let _datePart_ be TemporalObjectToISODateRecord(_dateTime_). 1. Let _dateDuration_ be ? AdjustDateDurationRecord(_normalizedDuration_.[[Date]], _timeResult_.[[Days]]). 1. Let _addedDate_ be ? CalendarDateAdd(_dateTime_.[[Calendar]], _datePart_, _dateDuration_, _overflow_). diff --git a/spec/plaintime.html b/spec/plaintime.html index 72c7ad460..5e7a3e022 100644 --- a/spec/plaintime.html +++ b/spec/plaintime.html @@ -882,12 +882,7 @@

AddTime ( - _hour_: an integer in the inclusive interval from 0 to 23, - _minute_: an integer in the inclusive interval from 0 to 59, - _second_: an integer in the inclusive interval from 0 to 59, - _millisecond_: an integer in the inclusive interval from 0 to 999, - _microsecond_: an integer in the inclusive interval from 0 to 999, - _nanosecond_: an integer in the inclusive interval from 0 to 999, + _time_: a Time Record _norm_: a Normalized Time Duration Record, ): a Time Record

@@ -896,9 +891,9 @@

- 1. Set _second_ to _second_ + NormalizedTimeDurationSeconds(_norm_). - 1. Set _nanosecond_ to _nanosecond_ + NormalizedTimeDurationSubseconds(_norm_). - 1. Return BalanceTime(_hour_, _minute_, _second_, _millisecond_, _microsecond_, _nanosecond_). + 1. Let _second_ be _time_.[[Second]] + NormalizedTimeDurationSeconds(_norm_). + 1. Let _nanosecond_ be _time_.[[Nanosecond]] + NormalizedTimeDurationSubseconds(_norm_). + 1. Return BalanceTime(_time_.[[Hour]], _time_.[[Minute]], _second_, _time_.[[Millisecond]], _time_.[[Microsecond]], _nanosecond_). @@ -1006,7 +1001,8 @@

1. Let _duration_ be ? ToTemporalDuration(_temporalDurationLike_). 1. If _operation_ is ~subtract~, set _duration_ to CreateNegatedTemporalDuration(_duration_). 1. Let _normalizedDuration_ be NormalizeDuration(_duration_). - 1. Let _result_ be AddTime(_temporalTime_.[[ISOHour]], _temporalTime_.[[ISOMinute]], _temporalTime_.[[ISOSecond]], _temporalTime_.[[ISOMillisecond]], _temporalTime_.[[ISOMicrosecond]], _temporalTime_.[[ISONanosecond]], _normalizedDuration_.[[NormalizedTime]]). + 1. Let _time_ be Time Record { [[Hour]]: _temporalTime_.[[ISOHour]], [[Minute]]: _temporalTime_.[[ISOMinute]], [[Second]]: _temporalTime_.[[ISOSecond]], [[Millisecond]]: _temporalTime_.[[ISOMillisecond]], [[Microsecond]]: _temporalTime_.[[ISOMicrosecond]], [[Nanosecond]]: _temporalTime_.[[ISONanosecond]] }. + 1. Let _result_ be AddTime(_time_, _normalizedDuration_.[[NormalizedTime]]). 1. Return ! CreateTemporalTime(_result_.[[Hour]], _result_.[[Minute]], _result_.[[Second]], _result_.[[Millisecond]], _result_.[[Microsecond]], _result_.[[Nanosecond]]). diff --git a/spec/timezone.html b/spec/timezone.html index c22315fd9..6ce6ee231 100644 --- a/spec/timezone.html +++ b/spec/timezone.html @@ -323,7 +323,8 @@

1. Assert: abs(_nanoseconds_) ≤ nsPerDay. 1. If _disambiguation_ is ~earlier~, then 1. Let _norm_ be NormalizeTimeDuration(0, 0, 0, 0, 0, -_nanoseconds_). - 1. Let _earlierTime_ be AddTime(_isoDateTime_.[[Hour]], _isoDateTime_.[[Minute]], _isoDateTime_.[[Second]], _isoDateTime_.[[Millisecond]], _isoDateTime_.[[Microsecond]], _isoDateTime_.[[Nanosecond]], _norm_). + 1. Let _time_ be Time Record { [[Hour]]: _isoDateTime_.[[Hour]], [[Minute]]: _isoDateTime_.[[Minute]], [[Second]]: _isoDateTime_.[[Second]], [[Millisecond]]: _isoDateTime_.[[Millisecond]], [[Microsecond]]: _isoDateTime_.[[Microsecond]], [[Nanosecond]]: _isoDateTime_.[[Nanosecond]] }. + 1. Let _earlierTime_ be AddTime(_time_, _norm_). 1. Let _earlierDate_ be BalanceISODate(_isoDateTime_.[[Year]], _isoDateTime_.[[Month]], _isoDateTime_.[[Day]] + _earlierTime_.[[Days]]). 1. Let _earlierDateTime_ be CombineISODateAndTimeRecord(_earlierDate_, _earlierTime_). 1. Set _possibleEpochNs_ to ? GetPossibleEpochNanoseconds(_timeZone_, _earlierDateTime_). @@ -331,7 +332,8 @@

1. Return _possibleEpochNs_[0]. 1. Assert: _disambiguation_ is ~compatible~ or ~later~. 1. Let _norm_ be NormalizeTimeDuration(0, 0, 0, 0, 0, _nanoseconds_). - 1. Let _laterTime_ be AddTime(_isoDateTime_.[[Hour]], _isoDateTime_.[[Minute]], _isoDateTime_.[[Second]], _isoDateTime_.[[Millisecond]], _isoDateTime_.[[Microsecond]], _isoDateTime_.[[Nanosecond]], _norm_). + 1. Let _time_ be Time Record { [[Hour]]: _isoDateTime_.[[Hour]], [[Minute]]: _isoDateTime_.[[Minute]], [[Second]]: _isoDateTime_.[[Second]], [[Millisecond]]: _isoDateTime_.[[Millisecond]], [[Microsecond]]: _isoDateTime_.[[Microsecond]], [[Nanosecond]]: _isoDateTime_.[[Nanosecond]] }. + 1. Let _laterTime_ be AddTime(_time_, _norm_). 1. Let _laterDate_ be BalanceISODate(_isoDateTime_.[[Year]], _isoDateTime_.[[Month]], _isoDateTime_.[[Day]] + _laterTime_.[[Days]]). 1. Let _laterDateTime_ be CombineISODateAndTimeRecord(_laterDate_, _laterTime_). 1. Set _possibleEpochNs_ to ? GetPossibleEpochNanoseconds(_timeZone_, _laterDateTime_).