Skip to content

Commit

Permalink
Normative: change ordering of balancing operations in Temporal.Durati…
Browse files Browse the repository at this point in the history
…on.prototype.round

If we balance the bigger units before the smaller ones, then we never
properly balance the days that are added from balancing units up to day
length. Changing the order of operations ensures proper balancing of all
units.
There is also no more need for the call to MoveRelativeZonedDateTime()
in the end of the method, so it's been removed.

Closes: #2508

UPSTREAM_COMMIT=36746e5ef8da4688237c195e51c8081e3304ab0f
  • Loading branch information
guijemont authored and justingrant committed Apr 26, 2023
1 parent 755c762 commit c8c41cf
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions lib/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,6 @@ export class Duration implements Temporal.Duration {
roundingMode,
relativeTo
));
({ years, months, weeks, days } = ES.BalanceDurationRelative(years, months, weeks, days, largestUnit, relativeTo));
if (ES.IsTemporalZonedDateTime(relativeTo)) {
relativeTo = ES.MoveRelativeZonedDateTime(relativeTo, years, months, weeks, 0);
}
({ days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds } = ES.BalanceDuration(
days,
hours,
Expand All @@ -323,6 +319,7 @@ export class Duration implements Temporal.Duration {
largestUnit,
relativeTo
));
({ years, months, weeks, days } = ES.BalanceDurationRelative(years, months, weeks, days, largestUnit, relativeTo));

return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds, microseconds, nanoseconds);
}
Expand Down

0 comments on commit c8c41cf

Please sign in to comment.