Skip to content
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

Normative: [Alt PR] Fix intermediate value in ZonedDateTime difference #2810

Merged

Commits on Mar 30, 2024

  1. 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.
    ptomato committed Mar 30, 2024
    Configuration menu
    Copy the full SHA
    682b7eb View commit details
    Browse the repository at this point in the history
  2. Updates to ZonedDateTime diffing algorithm and dayCorrection.

    Fixes bug mentioned here:
    tc39#2760 (comment)
    arshaw authored and ptomato committed Mar 30, 2024
    Configuration menu
    Copy the full SHA
    d7d158c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    ac1aa00 View commit details
    Browse the repository at this point in the history

Commits on Apr 2, 2024

  1. Update test262

    ptomato committed Apr 2, 2024
    Configuration menu
    Copy the full SHA
    3f30bd0 View commit details
    Browse the repository at this point in the history