Skip to content

Commit

Permalink
Temporal: Add test coverage for edge case in DST balancing after roun…
Browse files Browse the repository at this point in the history
…ding

This covers an edge case that we hit, where 24 hours would not balance up
to one day in a 25-hour day if only largestUnit was specified, but would
erroneously balance up if rounding was also performed by specifying
smallestUnit.
  • Loading branch information
ptomato committed May 13, 2024
1 parent 43c8790 commit 22e4548
Showing 1 changed file with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,20 @@ const timeZone = TemporalHelpers.springForwardFallBackTimeZone();
TemporalHelpers.assertDuration(result, 1, 0, 0, 0, 24, 0, 0, 0, 0, 0,
"24 hours does not balance to 1 day in 25-hour day");
}

{
const duration = new Temporal.Duration(0, 0, 0, 0, /* hours = */ 24, 0, 0, 0, 0, /* ns = */ 5);
const relativeTo = new Temporal.ZonedDateTime(
972802800_000_000_000n /* = 2000-10-29T07Z */,
timeZone); /* = 2000-10-29T00-07 in local time */

const result = duration.round({
largestUnit: "days",
smallestUnit: "minutes",
roundingMode: "expand",
roundingIncrement: 30,
relativeTo
});
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 24, 30, 0, 0, 0, 0,
"24 hours does not balance after rounding to 1 day in 25-hour day");
}

0 comments on commit 22e4548

Please sign in to comment.