Skip to content

Commit

Permalink
Editorial: Rename UnnormalizeDuration to TemporalDurationFromInternal
Browse files Browse the repository at this point in the history
See: #2953
  • Loading branch information
ptomato committed Oct 8, 2024
1 parent f9566a0 commit 19ea398
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 27 deletions.
11 changes: 7 additions & 4 deletions polyfill/lib/duration.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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
Expand All @@ -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');
Expand Down Expand Up @@ -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() {
Expand Down
18 changes: 9 additions & 9 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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))) {
Expand All @@ -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);
Expand Down Expand Up @@ -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) {
Expand Down
14 changes: 7 additions & 7 deletions spec/duration.html
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ <h1>Temporal.Duration.prototype.round ( _roundTo_ )</h1>
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]]).
Expand All @@ -444,12 +444,12 @@ <h1>Temporal.Duration.prototype.round ( _roundTo_ )</h1>
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_).
</emu-alg>
</emu-clause>

Expand Down Expand Up @@ -515,7 +515,7 @@ <h1>Temporal.Duration.prototype.toString ( [ _options_ ] )</h1>
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]]).
</emu-alg>
</emu-clause>
Expand Down Expand Up @@ -937,9 +937,9 @@ <h1>
</emu-alg>
</emu-clause>

<emu-clause id="sec-temporal-unnormalizeduration" type="abstract operation">
<emu-clause id="sec-temporal-temporaldurationfrominternal" type="abstract operation">
<h1>
UnnormalizeDuration (
TemporalDurationFromInternal (
_internalDuration_: an Internal Duration Record,
_largestUnit_: a Temporal unit,
): either a normal completion containing a Temporal.Duration, or a throw completion
Expand Down Expand Up @@ -2025,7 +2025,7 @@ <h1>
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_).
</emu-alg>
</emu-clause>
</emu-clause>
Expand Down
2 changes: 1 addition & 1 deletion spec/instant.html
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,7 @@ <h1>
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_.
</emu-alg>
Expand Down
2 changes: 1 addition & 1 deletion spec/plaindate.html
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ <h1>
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_.
</emu-alg>
Expand Down
2 changes: 1 addition & 1 deletion spec/plaindatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -1052,7 +1052,7 @@ <h1>
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_.
</emu-alg>
Expand Down
2 changes: 1 addition & 1 deletion spec/plaintime.html
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ <h1>
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_.
</emu-alg>
Expand Down
2 changes: 1 addition & 1 deletion spec/plainyearmonth.html
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,7 @@ <h1>
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_.
</emu-alg>
Expand Down
4 changes: 2 additions & 2 deletions spec/zoneddatetime.html
Original file line number Diff line number Diff line change
Expand Up @@ -1215,7 +1215,7 @@ <h1>
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.
Expand All @@ -1224,7 +1224,7 @@ <h1>
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_.
</emu-alg>
Expand Down

0 comments on commit 19ea398

Please sign in to comment.