Repository navigation
Add the years and months of a Period at once in LocalDate::plusPeriod() - #141
Merged
Merged
Conversation
plusPeriod() added the years, then the months, so a Feb 29 was clamped by
both steps, and an intermediate year could be out of range even when the
result was valid:
LocalDate::of(2020, 2, 29)->plusPeriod(Period::of(1, 1, 0)); // 2021-03-28 instead of 2021-03-29
LocalDate::of(999995, 2, 26)->plusPeriod(Period::of(5, -29, 5)); // "Invalid year: 1000000"
It now adds the total number of months in one step, as java.time does.
LocalDateTime and ZonedDateTime::plusPeriod() go through it.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #141 +/- ##
=========================================
Coverage 99.24% 99.24%
Complexity 1141 1141
=========================================
Files 48 48
Lines 2501 2501
=========================================
Hits 2482 2482
Misses 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA
Member
|
Thank you, @gnutix! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Item 2 of #137.
Problem
LocalDate::plusPeriod()calledplusYears(), thenplusMonths(), so a Feb 29 was clamped by both steps:Change
The years and months are added as a single number of months, as
java.timedoes (plusMonths(toTotalMonths())), then the days.LocalDateTime::plusPeriod()andZonedDateTime::plusPeriod()delegate to it, andminusPeriod()goes through it.New cases in the
providerPeriodofLocalDateTestandLocalDateTimeTest, used by bothplusPeriodandminusPeriod.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA