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: Fix Duration rounding relative to ZonedDateTime #2758

Merged
merged 4 commits into from
May 14, 2024

Commits on May 6, 2024

  1. Normative: Fix Duration rounding relative to ZonedDateTime

    When the time portion of a duration, rounded relative to a ZonedDateTime,
    would land on a non-24-hour day, we'd get incorrect results. This is a
    regression from #2508 where although switching the order of
    BalanceDateDurationRelative and BalanceTimeDurationRelative was correct,
    we should not have removed the MoveRelativeZonedDateTime call.
    
    Closes: #2742
    ptomato committed May 6, 2024
    Configuration menu
    Copy the full SHA
    bbfb1c4 View commit details
    Browse the repository at this point in the history
  2. Normative: Combine code paths for duration rounding and difference

    In order to prevent bugs due to discrepancies between two ways of
    calculating the same thing such as in #2742, refactor duration rounding
    with relativeTo so that
    
        duration.round({ smallestUnit, largestUnit, relativeTo, ...options })
    
    goes through the same code path and gives the same result as
    
        const target = relativeTo.add(duration);
        relativeTo.until(target, { smallestUnit, largestUnit, ...options })
    
    but taking into account that the until() methods have a different default
    roundingMode than Duration.prototype.round(), and optimizing away as many
    user-observable calls as possible.
    
    Similarly,
    
        duration.total({ unit, relativeTo, ...options })
    
    goes through the same code path, which also returns the total as a
    mathematical value if needed.
    ptomato committed May 6, 2024
    Configuration menu
    Copy the full SHA
    b4b21b3 View commit details
    Browse the repository at this point in the history

Commits on May 13, 2024

  1. Normative: Implement optimizations in shared duration rounding code path

    These optimizations were developed by Adam Shaw:
    https://gist.github.com/arshaw/36d3152c21482bcb78ea2c69591b20e0
    
    It does the same thing as previously, although fixes some incidental edge
    cases that Adam discovered. However, the algorithm is simpler to explain
    and to understand, and also makes fewer calls into user code.
    
    It uses three variations on a bounding technique for rounding: computing
    the upper and lower result, and checking which one is closer to the
    original duration, and 'nudging' the duration up or down accordingly.
    
    There is one variation for calendar units, one variation for rounding
    relative to a ZonedDateTime where smallestUnit is a time unit and
    largestUnit is a calendar unit, and one variation for time units.
    
    RoundDuration becomes a lot more simplified, any part of it that was
    complex is now split out into the new RoundRelativeDuration and
    BubbleRelativeDuration operations, and the three 'nudging' operations.
    
    The operations NormalizedTimeDurationToDays, BalanceTimeDurationRelative,
    BalanceDateDurationRelative, MoveRelativeDate, MoveRelativeZonedDateTime,
    and AdjustRoundedDurationDays are no longer needed. Their functionality is
    subsumed by the new operations.
    
    Closes: #2792
    Closes: #2817
    ptomato committed May 13, 2024
    Configuration menu
    Copy the full SHA
    4bf121c View commit details
    Browse the repository at this point in the history

Commits on May 14, 2024

  1. Update test262

    ptomato committed May 14, 2024
    Configuration menu
    Copy the full SHA
    55439c6 View commit details
    Browse the repository at this point in the history