From 19ea398639f4e5b4b60137fc755d65f682b6fbce Mon Sep 17 00:00:00 2001 From: Philip Chimento Date: Tue, 8 Oct 2024 10:43:40 -0700 Subject: [PATCH] Editorial: Rename UnnormalizeDuration to TemporalDurationFromInternal See: #2953 --- polyfill/lib/duration.mjs | 11 +++++++---- polyfill/lib/ecmascript.mjs | 18 +++++++++--------- spec/duration.html | 14 +++++++------- spec/instant.html | 2 +- spec/plaindate.html | 2 +- spec/plaindatetime.html | 2 +- spec/plaintime.html | 2 +- spec/plainyearmonth.html | 2 +- spec/zoneddatetime.html | 4 ++-- 9 files changed, 30 insertions(+), 27 deletions(-) diff --git a/polyfill/lib/duration.mjs b/polyfill/lib/duration.mjs index be4945833..90bc26d06 100644 --- a/polyfill/lib/duration.mjs +++ b/polyfill/lib/duration.mjs @@ -247,7 +247,7 @@ export class Duration { roundingMode ); if (ES.TemporalUnitCategory(largestUnit) === 'date') largestUnit = 'hour'; - return ES.UnnormalizeDuration(duration, largestUnit); + return ES.TemporalDurationFromInternal(duration, largestUnit); } if (plainRelativeTo) { @@ -271,7 +271,7 @@ export class Duration { smallestUnit, roundingMode ); - return ES.UnnormalizeDuration(duration, largestUnit); + return ES.TemporalDurationFromInternal(duration, largestUnit); } // No reference date to calculate difference relative to @@ -284,7 +284,7 @@ export class Duration { assert(!ES.IsCalendarUnit(smallestUnit), 'smallestUnit was larger than largestUnit'); let duration = ES.ToInternalDurationRecordWith24HourDays(this); duration = ES.RoundTimeDuration(duration, roundingIncrement, smallestUnit, roundingMode); - return ES.UnnormalizeDuration(duration, largestUnit); + return ES.TemporalDurationFromInternal(duration, largestUnit); } total(totalOf) { if (!ES.IsTemporalDuration(this)) throw new TypeErrorCtor('invalid receiver'); @@ -351,7 +351,10 @@ export class Duration { const largestUnit = ES.DefaultTemporalLargestUnit(this); let duration = ES.ToInternalDurationRecord(this); duration = ES.RoundTimeDuration(duration, increment, unit, roundingMode); - const roundedDuration = ES.UnnormalizeDuration(duration, ES.LargerOfTwoTemporalUnits(largestUnit, 'second')); + const roundedDuration = ES.TemporalDurationFromInternal( + duration, + ES.LargerOfTwoTemporalUnits(largestUnit, 'second') + ); return ES.TemporalDurationToString(roundedDuration, precision); } toJSON() { diff --git a/polyfill/lib/ecmascript.mjs b/polyfill/lib/ecmascript.mjs index 1efab3b57..6999019e2 100644 --- a/polyfill/lib/ecmascript.mjs +++ b/polyfill/lib/ecmascript.mjs @@ -2871,7 +2871,7 @@ function ToDateDurationRecordWithoutTime(duration) { return { ...internalDuration.date, days }; } -export function UnnormalizeDuration(internalDuration, largestUnit) { +export function TemporalDurationFromInternal(internalDuration, largestUnit) { const sign = internalDuration.norm.sign(); let nanoseconds = internalDuration.norm.abs().subsec; let microseconds = 0; @@ -3603,7 +3603,7 @@ export function DifferenceTemporalInstant(operation, instant, other, options) { settings.smallestUnit, settings.roundingMode ); - let result = UnnormalizeDuration(duration, settings.largestUnit); + let result = TemporalDurationFromInternal(duration, settings.largestUnit); if (operation === 'since') result = CreateNegatedTemporalDuration(result); return result; } @@ -3645,7 +3645,7 @@ export function DifferenceTemporalPlainDate(operation, plainDate, other, options ); } - let result = UnnormalizeDuration(duration, 'day'); + let result = TemporalDurationFromInternal(duration, 'day'); if (operation === 'since') result = CreateNegatedTemporalDuration(result); return result; } @@ -3676,7 +3676,7 @@ export function DifferenceTemporalPlainDateTime(operation, plainDateTime, other, settings.roundingMode ); - let result = UnnormalizeDuration(duration, settings.largestUnit); + let result = TemporalDurationFromInternal(duration, settings.largestUnit); if (operation === 'since') result = CreateNegatedTemporalDuration(result); return result; } @@ -3693,7 +3693,7 @@ export function DifferenceTemporalPlainTime(operation, plainTime, other, options duration = RoundTimeDuration(duration, settings.roundingIncrement, settings.smallestUnit, settings.roundingMode); } - let result = UnnormalizeDuration(duration, settings.largestUnit); + let result = TemporalDurationFromInternal(duration, settings.largestUnit); if (operation === 'since') result = CreateNegatedTemporalDuration(result); return result; } @@ -3740,7 +3740,7 @@ export function DifferenceTemporalPlainYearMonth(operation, yearMonth, other, op ); } - let result = UnnormalizeDuration(duration, 'day'); + let result = TemporalDurationFromInternal(duration, 'day'); if (operation === 'since') result = CreateNegatedTemporalDuration(result); return result; } @@ -3771,7 +3771,7 @@ export function DifferenceTemporalZonedDateTime(operation, zonedDateTime, other, settings.smallestUnit, settings.roundingMode ); - result = UnnormalizeDuration(duration, settings.largestUnit); + result = TemporalDurationFromInternal(duration, settings.largestUnit); } else { const timeZone = GetSlot(zonedDateTime, TIME_ZONE); if (!TimeZoneEquals(timeZone, GetSlot(other, TIME_ZONE))) { @@ -3793,7 +3793,7 @@ export function DifferenceTemporalZonedDateTime(operation, zonedDateTime, other, settings.smallestUnit, settings.roundingMode ); - result = UnnormalizeDuration(duration, 'hour'); + result = TemporalDurationFromInternal(duration, 'hour'); } if (operation === 'since') result = CreateNegatedTemporalDuration(result); @@ -3851,7 +3851,7 @@ export function AddDurations(operation, duration, other) { const d1 = ToInternalDurationRecordWith24HourDays(duration); const d2 = ToInternalDurationRecordWith24HourDays(other); const result = CombineDateAndNormalizedTimeDuration(ZeroDateDuration(), d1.norm.add(d2.norm)); - return UnnormalizeDuration(result, largestUnit); + return TemporalDurationFromInternal(result, largestUnit); } export function AddDurationToInstant(operation, instant, durationLike) { diff --git a/spec/duration.html b/spec/duration.html index 2519c9650..0f53d7d0e 100644 --- a/spec/duration.html +++ b/spec/duration.html @@ -434,7 +434,7 @@

Temporal.Duration.prototype.round ( _roundTo_ )

1. Let _targetEpochNs_ be ? AddZonedDateTime(_relativeEpochNs_, _timeZone_, _calendar_, _internalDuration_, ~constrain~). 1. Set _internalDuration_ to ? DifferenceZonedDateTimeWithRounding(_relativeEpochNs_, _targetEpochNs_, _timeZone_, _calendar_, _largestUnit_, _roundingIncrement_, _smallestUnit_, _roundingMode_). 1. If TemporalUnitCategory(_largestUnit_) is ~date~, set _largestUnit_ to ~hour~. - 1. Return ? UnnormalizeDuration(_internalDuration_, _largestUnit_). + 1. Return ? TemporalDurationFromInternal(_internalDuration_, _largestUnit_). 1. If _plainRelativeTo_ is not *undefined*, then 1. Let _internalDuration_ be ToInternalDurationRecordWith24HourDays(_duration_). 1. Let _targetTime_ be AddTime(MidnightTimeRecord(), _internalDuration_.[[NormalizedTime]]). @@ -444,12 +444,12 @@

Temporal.Duration.prototype.round ( _roundTo_ )

1. Let _isoDateTime_ be CombineISODateAndTimeRecord(_plainRelativeTo_.[[ISODate]], MidnightTimeRecord()). 1. Let _targetDateTime_ be CombineISODateAndTimeRecord(_targetDate_, _targetTime_). 1. Set _internalDuration_ to ? DifferencePlainDateTimeWithRounding(_isoDateTime_, _targetDateTime_, _calendar_, _largestUnit_, _roundingIncrement_, _smallestUnit_, _roundingMode_). - 1. Return ? UnnormalizeDuration(_internalDuration_, _largestUnit_). + 1. Return ? TemporalDurationFromInternal(_internalDuration_, _largestUnit_). 1. If IsCalendarUnit(_existingLargestUnit_) is *true*, or IsCalendarUnit(_largestUnit_) is *true*, throw a *RangeError* exception. 1. Assert: IsCalendarUnit(_smallestUnit_) is *false*. 1. Let _internalDuration_ be ToInternalDurationRecordWith24HourDays(_duration_). 1. Set _internalDuration_ to ? RoundTimeDuration(_internalDuration_, _roundingIncrement_, _smallestUnit_, _roundingMode_). - 1. Return ? UnnormalizeDuration(_internalDuration_, _largestUnit_). + 1. Return ? TemporalDurationFromInternal(_internalDuration_, _largestUnit_). @@ -515,7 +515,7 @@

Temporal.Duration.prototype.toString ( [ _options_ ] )

1. Let _internalDuration_ be ToInternalDurationRecord(_duration_). 1. Set _internalDuration_ to ? RoundTimeDuration(_internalDuration_, _precision_.[[Increment]], _precision_.[[Unit]], _roundingMode_). 1. Let _roundedLargestUnit_ be LargerOfTwoTemporalUnits(_largestUnit_, ~second~). - 1. Let _roundedDuration_ be ! UnnormalizeDuration(_internalDuration_, _roundedLargestUnit_). + 1. Let _roundedDuration_ be ! TemporalDurationFromInternal(_internalDuration_, _roundedLargestUnit_). 1. Return TemporalDurationToString(_roundedDuration_, _precision_.[[Precision]]). @@ -937,9 +937,9 @@

- +

- UnnormalizeDuration ( + TemporalDurationFromInternal ( _internalDuration_: an Internal Duration Record, _largestUnit_: a Temporal unit, ): either a normal completion containing a Temporal.Duration, or a throw completion @@ -2025,7 +2025,7 @@

1. Let _d2_ be ToInternalDurationRecordWith24HourDays(_other_). 1. Let _normResult_ be ? AddNormalizedTimeDuration(_d1_.[[NormalizedTime]], _d2_.[[NormalizedTime]]). 1. Let _result_ be ! CombineDateAndNormalizedTimeDuration(ZeroDateDuration(), _normResult_). - 1. Return ? UnnormalizeDuration(_result_, _largestUnit_). + 1. Return ? TemporalDurationFromInternal(_result_, _largestUnit_). diff --git a/spec/instant.html b/spec/instant.html index 3f3757574..0b730537a 100644 --- a/spec/instant.html +++ b/spec/instant.html @@ -543,7 +543,7 @@

1. Let _resolvedOptions_ be ? GetOptionsObject(_options_). 1. Let _settings_ be ? GetDifferenceSettings(_operation_, _resolvedOptions_, ~time~, « », ~nanosecond~, ~second~). 1. Let _internalDuration_ be DifferenceInstant(_instant_.[[EpochNanoseconds]], _other_.[[EpochNanoseconds]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]]). - 1. Let _result_ be ! UnnormalizeDuration(_internalDuration_, _settings_.[[LargestUnit]]). + 1. Let _result_ be ! TemporalDurationFromInternal(_internalDuration_, _settings_.[[LargestUnit]]). 1. If _operation_ is ~since~, set _result_ to CreateNegatedTemporalDuration(_result_). 1. Return _result_. diff --git a/spec/plaindate.html b/spec/plaindate.html index 5ac55a00a..831f69c08 100644 --- a/spec/plaindate.html +++ b/spec/plaindate.html @@ -904,7 +904,7 @@

1. Let _isoDateTimeOther_ be CombineISODateAndTimeRecord(_other_.[[ISODate]], MidnightTimeRecord()). 1. Let _destEpochNs_ be GetUTCEpochNanoseconds(_isoDateTimeOther_). 1. Set _duration_ to ? RoundRelativeDuration(_duration_, _destEpochNs_, _isoDateTime_, ~unset~, _temporalDate_.[[Calendar]], _settings_.[[LargestUnit]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]]). - 1. Let _result_ be ! UnnormalizeDuration(_duration_, ~day~). + 1. Let _result_ be ! TemporalDurationFromInternal(_duration_, ~day~). 1. If _operation_ is ~since~, set _result_ to CreateNegatedTemporalDuration(_result_). 1. Return _result_. diff --git a/spec/plaindatetime.html b/spec/plaindatetime.html index 093cc4a69..e56a718e5 100644 --- a/spec/plaindatetime.html +++ b/spec/plaindatetime.html @@ -1052,7 +1052,7 @@

1. If CompareISODateTime(_dateTime_.[[ISODateTime]], _other_.[[ISODateTime]]) = 0, then 1. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0). 1. Let _internalDuration_ be ? DifferencePlainDateTimeWithRounding(_dateTime_.[[ISODateTime]], _other_.[[ISODateTime]], _dateTime_.[[Calendar]], _settings_.[[LargestUnit]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]]). - 1. Let _result_ be ? UnnormalizeDuration(_internalDuration_, _settings_.[[LargestUnit]]). + 1. Let _result_ be ? TemporalDurationFromInternal(_internalDuration_, _settings_.[[LargestUnit]]). 1. If _operation_ is ~since~, set _result_ to CreateNegatedTemporalDuration(_result_). 1. Return _result_. diff --git a/spec/plaintime.html b/spec/plaintime.html index 2dfef811f..f1a1c6ec3 100644 --- a/spec/plaintime.html +++ b/spec/plaintime.html @@ -935,7 +935,7 @@

1. Let _duration_ be ! CombineDateAndNormalizedTimeDuration(ZeroDateDuration(), _norm_). 1. If _settings_.[[SmallestUnit]] is not ~nanosecond~ or _settings_.[[RoundingIncrement]] ≠ 1, then 1. Set _duration_ to ! RoundTimeDuration(_duration_, _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]]). - 1. Let _result_ be ! UnnormalizeDuration(_duration_, _settings_.[[LargestUnit]]). + 1. Let _result_ be ! TemporalDurationFromInternal(_duration_, _settings_.[[LargestUnit]]). 1. If _operation_ is ~since~, set _result_ to CreateNegatedTemporalDuration(_result_). 1. Return _result_. diff --git a/spec/plainyearmonth.html b/spec/plainyearmonth.html index 53d363615..8f2a0e5bf 100644 --- a/spec/plainyearmonth.html +++ b/spec/plainyearmonth.html @@ -616,7 +616,7 @@

1. Let _isoDateTimeOther_ be CombineISODateAndTimeRecord(_otherDate_, MidnightTimeRecord()). 1. Let _destEpochNs_ be GetUTCEpochNanoseconds(_isoDateTimeOther_). 1. Set _duration_ to ? RoundRelativeDuration(_duration_, _destEpochNs_, _isoDateTime_, ~unset~, _calendar_, _settings_.[[LargestUnit]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]]).[[Duration]]. - 1. Let _result_ be ? UnnormalizeDuration(_duration_, ~day~). + 1. Let _result_ be ? TemporalDurationFromInternal(_duration_, ~day~). 1. If _operation_ is ~since~, set _result_ to CreateNegatedTemporalDuration(_result_). 1. Return _result_. diff --git a/spec/zoneddatetime.html b/spec/zoneddatetime.html index 32732d799..6c1e3aca6 100644 --- a/spec/zoneddatetime.html +++ b/spec/zoneddatetime.html @@ -1215,7 +1215,7 @@

1. Let _settings_ be ? GetDifferenceSettings(_operation_, _resolvedOptions_, ~datetime~, « », ~nanosecond~, ~hour~). 1. If TemporalUnitCategory(_settings_.[[LargestUnit]]) is not ~date~, then 1. Let _internalDuration_ be DifferenceInstant(_zonedDateTime_.[[EpochNanoseconds]], _other_.[[EpochNanoseconds]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]]). - 1. Let _result_ be ! UnnormalizeDuration(_internalDuration_, _settings_.[[LargestUnit]]). + 1. Let _result_ be ! TemporalDurationFromInternal(_internalDuration_, _settings_.[[LargestUnit]]). 1. If _operation_ is ~since~, set _result_ to CreateNegatedTemporalDuration(_result_). 1. Return _result_. 1. NOTE: To calculate differences in two different time zones, _settings_.[[LargestUnit]] must be a time unit, because day lengths can vary between time zones due to DST and other UTC offset shifts. @@ -1224,7 +1224,7 @@

1. If _zonedDateTime_.[[EpochNanoseconds]] = _other_.[[EpochNanoseconds]], then 1. Return ! CreateTemporalDuration(0, 0, 0, 0, 0, 0, 0, 0, 0, 0). 1. Let _internalDuration_ be ? DifferenceZonedDateTimeWithRounding(_zonedDateTime_.[[EpochNanoseconds]], _other_.[[EpochNanoseconds]], _zonedDateTime_.[[TimeZone]], _zonedDateTime_.[[Calendar]], _settings_.[[LargestUnit]], _settings_.[[RoundingIncrement]], _settings_.[[SmallestUnit]], _settings_.[[RoundingMode]]). - 1. Let _result_ be ? UnnormalizeDuration(_internalDuration_, ~hour~). + 1. Let _result_ be ? TemporalDurationFromInternal(_internalDuration_, ~hour~). 1. If _operation_ is ~since~, set _result_ to CreateNegatedTemporalDuration(_result_). 1. Return _result_.