Skip to content

Commit

Permalink
Fix compare for dates with unusual number of hours
Browse files Browse the repository at this point in the history
Thanks to DST, some dates in a year may have more or less
than 24 hours. We need to change the implementation of
`Duration.compare` when handling such cases. The solution is
to work only with years, months, weeks, and days; working
with more fine-grained data (hours, minutes, etc.) might be
mistaken in such cases because they may contain the
assumption that all days have 24 hours.

Thanks @justingrant for the solution!

closes #1791

UPSTREAM_COMMIT=08bcd53860aacb95c91aa67e5c9bd14abe116229
  • Loading branch information
jessealama authored and 12wrigja committed Jul 6, 2022
1 parent 34662a0 commit a4c6024
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/duration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,8 @@ export class Duration implements Temporal.Duration {
const ms2 = GetSlot(two, MILLISECONDS);
const µs2 = GetSlot(two, MICROSECONDS);
let ns2 = GetSlot(two, NANOSECONDS);
const shift1 = ES.CalculateOffsetShift(relativeTo, y1, mon1, w1, d1, h1, min1, s1, ms1, µs1, ns1);
const shift2 = ES.CalculateOffsetShift(relativeTo, y2, mon2, w2, d2, h2, min2, s2, ms2, µs2, ns2);
const shift1 = ES.CalculateOffsetShift(relativeTo, y1, mon1, w1, d1, 0, 0, 0, 0, 0, 0);
const shift2 = ES.CalculateOffsetShift(relativeTo, y2, mon2, w2, d2, 0, 0, 0, 0, 0, 0);
if (y1 !== 0 || y2 !== 0 || mon1 !== 0 || mon2 !== 0 || w1 !== 0 || w2 !== 0) {
({ days: d1 } = ES.UnbalanceDurationRelative(y1, mon1, w1, d1, 'day', relativeTo));
({ days: d2 } = ES.UnbalanceDurationRelative(y2, mon2, w2, d2, 'day', relativeTo));
Expand Down

0 comments on commit a4c6024

Please sign in to comment.