Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
- Loading branch information