Skip to content

Commit

Permalink
Editorial: Rename roundedNorm/diffNorm to roundedTime/diffTime
Browse files Browse the repository at this point in the history
These were holdovers from the old terminology.

Closes: #3016
  • Loading branch information
ptomato committed Nov 11, 2024
1 parent 48581b3 commit 48634bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
12 changes: 6 additions & 6 deletions polyfill/lib/ecmascript.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3270,21 +3270,21 @@ function NudgeToDayOrTime(duration, destEpochNs, largestUnit, increment, smalles
const timeDuration = duration.time.add24HourDays(duration.date.days);
// Convert to nanoseconds and round
const unitLength = Call(MapPrototypeGet, NS_PER_TIME_UNIT, [smallestUnit]);
const roundedNorm = timeDuration.round(increment * unitLength, roundingMode);
const diffNorm = roundedNorm.subtract(timeDuration);
const roundedTime = timeDuration.round(increment * unitLength, roundingMode);
const diffTime = roundedTime.subtract(timeDuration);

// Determine if whole days expanded
const { quotient: wholeDays } = timeDuration.divmod(DAY_NANOS);
const { quotient: roundedWholeDays } = roundedNorm.divmod(DAY_NANOS);
const { quotient: roundedWholeDays } = roundedTime.divmod(DAY_NANOS);
const didExpandDays = MathSign(roundedWholeDays - wholeDays) === timeDuration.sign();

const nudgedEpochNs = diffNorm.addToEpochNs(destEpochNs);
const nudgedEpochNs = diffTime.addToEpochNs(destEpochNs);

let days = 0;
let remainder = roundedNorm;
let remainder = roundedTime;
if (TemporalUnitCategory(largestUnit) === 'date') {
days = roundedWholeDays;
remainder = roundedNorm.add(TimeDuration.fromComponents(-roundedWholeDays * 24, 0, 0, 0, 0, 0));
remainder = roundedTime.add(TimeDuration.fromComponents(-roundedWholeDays * 24, 0, 0, 0, 0, 0));
}

const dateDuration = AdjustDateDurationRecord(duration.date, days);
Expand Down
12 changes: 6 additions & 6 deletions spec/duration.html
Original file line number Diff line number Diff line change
Expand Up @@ -1737,19 +1737,19 @@ <h1>
<emu-alg>
1. Let _timeDuration_ be ! Add24HourDaysToTimeDuration(_duration_.[[Time]], _duration_.[[Date]].[[Days]]).
1. Let _unitLength_ be the value in the "Length in Nanoseconds" column of the row of <emu-xref href="#table-temporal-units"></emu-xref> whose "Value" column contains _smallestUnit_.
1. Let _roundedNorm_ be ? RoundTimeDurationToIncrement(_timeDuration_, _unitLength_ × _increment_, _roundingMode_).
1. Let _diffNorm_ be ! AddTimeDuration(_roundedNorm_, -_timeDuration_).
1. Let _roundedTime_ be ? RoundTimeDurationToIncrement(_timeDuration_, _unitLength_ × _increment_, _roundingMode_).
1. Let _diffTime_ be ! AddTimeDuration(_roundedTime_, -_timeDuration_).
1. Let _wholeDays_ be truncate(DivideTimeDuration(_timeDuration_, nsPerDay)).
1. Let _roundedWholeDays_ be truncate(DivideTimeDuration(_roundedNorm_, nsPerDay)).
1. Let _roundedWholeDays_ be truncate(DivideTimeDuration(_roundedTime_, nsPerDay)).
1. Let _dayDelta_ be _roundedWholeDays_ - _wholeDays_.
1. If _dayDelta_ &lt; 0, let _dayDeltaSign_ be -1; else if _dayDelta_ > 0, let _dayDeltaSign_ be 1; else let _dayDeltaSign_ be 0.
1. If _dayDeltaSign_ = TimeDurationSign(_timeDuration_), let _didExpandDays_ be *true*; else let _didExpandDays_ be *false*.
1. Let _nudgedEpochNs_ be AddTimeDurationToEpochNanoseconds(_diffNorm_, _destEpochNs_).
1. Let _nudgedEpochNs_ be AddTimeDurationToEpochNanoseconds(_diffTime_, _destEpochNs_).
1. Let _days_ be 0.
1. Let _remainder_ be _roundedNorm_.
1. Let _remainder_ be _roundedTime_.
1. If TemporalUnitCategory(_largestUnit_) is ~date~, then
1. Set _days_ to _roundedWholeDays_.
1. Set _remainder_ to ! AddTimeDuration(_roundedNorm_, TimeDurationFromComponents(-_roundedWholeDays_ * HoursPerDay, 0, 0, 0, 0, 0)).
1. Set _remainder_ to ! AddTimeDuration(_roundedTime_, TimeDurationFromComponents(-_roundedWholeDays_ * HoursPerDay, 0, 0, 0, 0, 0)).
1. Let _dateDuration_ be ? AdjustDateDurationRecord(_duration_.[[Date]], _days_).
1. Let _resultDuration_ be ? CombineDateAndTimeDuration(_dateDuration_, _remainder_).
1. Return Duration Nudge Result Record { [[Duration]]: _resultDuration_, [[NudgedEpochNs]]: _nudgedEpochNs_, [[DidExpandCalendarUnit]]: _didExpandDays_ }.
Expand Down

0 comments on commit 48634bd

Please sign in to comment.