Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normative: Fix intermediate value in ZonedDateTime difference
To find the difference between two ZonedDateTimes, we first find the calendar difference between their date parts. Then we find the time difference between an intermediate ZonedDateTime value (calculated by adding the calendar parts to the first ZonedDateTime) and the second ZonedDateTime. Previously we would calculate the intermediate value by adding years, months, and weeks from the date difference, because the days were calculated as part of the time difference. This was incorrect, because the intermediate value can shift if it falls in the middle of a DST transition. However, that could be on a completely different date than would be expected, leading to surprising results like this: const duration = Temporal.Duration.from({ months: 1, days: 15, hours: 12 }); const past = Temporal.ZonedDateTime.from('2024-02-10T02:00[America/New_York]'); const future = past.add(duration); duration // => 1 month, 15 days, 12 hours past.until(future, { largestUnit: 'months' }) // => 1 month, 15 days, 11 hours This result would occur because of a DST change on 2024-03-10T02:00, unrelated to either the start date of 2024-02-10 or the end date of 2024-03-25. With this change, the intermediate value occurs on 2024-03-25T02:00 and would only shift if that was when the DST change occurred.
- Loading branch information