-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duration::round
incorrectly bubbling time units for DST gaps
#2816
Comments
With the fullcalendar polyfill as well as the new algorithm in #2758 I get the same results: const dur = Temporal.Duration.from({ months: -1, hours: -24 });
const relativeTo = Temporal.ZonedDateTime.from('2024-04-11T02:00:00[America/New_York]');
const result = dur.round({
smallestUnit: 'millisecond',
relativeTo
});
console.log(result.toString()); // -P1M1DT1H
const end = relativeTo.add(dur);
console.log(end.toString()); // 2024-03-10T01:00:00-05:00[America/New_York]
console.log(relativeTo.until(end, { largestUnit: 'months' }).toString()); // -P1M1DT1H So the original bug seems like it is fixed, but the result is still different from the expectation above. At first glance it seems like -P1MT23H might be wrong? Subtracting 1 month from 2024-04-11T02 gives 2024-03-11T02, and subtracting another 23 hours from that gives either 2024-03-10T03 or 2024-03-10T02; but adding the original duration gives 2024-03-10T01. |
I was wrong about what the EXPECTED case should be. Corrected: dur = Temporal.Duration.from({ months: -1, hours: -24 })
relativeTo = Temporal.ZonedDateTime.from('2024-04-11T02:00:00[America/New_York]')
// fyi, 2024-03-10T02:00:00 is a spring-forward DST gap
//
dur.round({ smallestUnit: 'millisecond', relativeTo }).toString()
//
// EXPECTED: -P1M1DT1H
// ACTUAL: -P1MT1H (looses a whole day!)
// The "EXPECTED" is correct because:
//
d2 = relativeTo.add({ months: -1, hours: -24 }) // '2024-03-10T01:00:00-05:00[America/New_York]'
//
relativeTo
.until(d2, { largestUnit: 'months' })
.toString() // -P1M1DT1H So, the original bug has been fixed, and the correct result is represented in the |
Yep, I agree with your reasoning. Glad this is fixed! |
This has a distinct root cause from #2742, not fixed by #2810.
Repro:
This bug also exists in fullcalendar's temporal-polyfill but for different reasons.
The text was updated successfully, but these errors were encountered: