Repository navigation
Fix LocalDateTime::plusDuration() when the nano carry crosses midnight - #142
Merged
BenMorel merged 1 commit intoOct 10, 2026
Merged
Conversation
The day shift was computed from the seconds only, while the time part
(LocalTime::plusDuration()) also applies the carry from the nanos. When that
carry crossed midnight, the time wrapped but the date did not move:
LocalDateTime::of(2000, 1, 1, 23, 59, 59, 500_000_000)->plusDuration(Duration::ofMillis(600));
// 2000-01-01T00:00:00.1 instead of 2000-01-02T00:00:00.1
LocalDateTime::of(2000, 1, 1, 0, 0, 0, 500_000_000)->minusDuration(Duration::ofMillis(400));
// 1999-12-31T00:00:00.1 instead of 2000-01-01T00:00:00.1
The second case comes from negative fractional durations, which are stored
as negative seconds and positive nanos.
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 #142 +/- ##
=========================================
Coverage 99.24% 99.24%
Complexity 1141 1141
=========================================
Files 48 48
Lines 2501 2503 +2
=========================================
+ Hits 2482 2484 +2
Misses 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Thank you, @gnutix! |
BenMorel
added a commit
that referenced
this pull request
Oct 10, 2026
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 3 of #137.
Problem
LocalDateTime::plusDuration()/minusDuration()landed on the wrong day when adding the nanos carried a second across midnight:The day shift was computed from the seconds only, while
LocalTime::plusDuration()applies the nano carry. The second case comes from how a negative fractional duration is stored: -0.4 s is (-1 s, +600,000,000 ns). This only happens when both the date-time and the duration have a fractional second.Change
The day shift now includes the carry,
intdiv(nano + duration nanos, NANOS_PER_SECOND). It is never negative, because both nano values are in[0, 1e9).There are two new cases in
providerDuration, which bothtestPlusDurationandtestMinusDurationuse: one crossing midnight forwards and one backwards.🤖 Generated with Claude Code
https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA