Skip to content

Commit

Permalink
FULLCALENDAR- since relativeTo:zoneddatetime with smallestUnit:days n…
Browse files Browse the repository at this point in the history
…eeds to compute epochns-range, out-of-range instant can happen
  • Loading branch information
arshaw committed Apr 13, 2024
1 parent cfc7b51 commit 887e0b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ const earlier = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC");
const result = later.since(earlier, { roundingIncrement: 2.5, roundingMode: "trunc" });
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2");
const result2 = later.since(earlier, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");

// I would argue RangeError should be thrown because this operation is out-of-range:
// new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC").add({ days: -1e9 })
// We need to compute epochNanosecond start/end of range because Zoned days could be irregular
assert.throws(RangeError, () => {
const result2 = later.since(earlier, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");
});
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,11 @@ const earlier = new Temporal.ZonedDateTime(1_000_000_000_000_000_000n, "UTC");
const later = new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC");
const result = earlier.until(later, { roundingIncrement: 2.5, roundingMode: "trunc" });
TemporalHelpers.assertDuration(result, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, "roundingIncrement 2.5 truncates to 2");
const result2 = earlier.until(later, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");

// I would argue RangeError should be thrown because this operation is out-of-range:
// new Temporal.ZonedDateTime(1_000_000_000_000_000_005n, "UTC").add({ days: -1e9 })
// We need to compute epochNanosecond start/end of range because Zoned days could be irregular
assert.throws(RangeError, () => {
const result2 = earlier.until(later, { smallestUnit: "days", roundingIncrement: 1e9 + 0.5, roundingMode: "expand" });
TemporalHelpers.assertDuration(result2, 0, 0, 0, 1e9, 0, 0, 0, 0, 0, 0, "roundingIncrement 1e9 + 0.5 truncates to 1e9");
});

0 comments on commit 887e0b5

Please sign in to comment.