Repository navigation
Fix LocalDateTime::plusNanos() and minusNanos() within the same second - #136
Merged
Merged
Conversation
plusWithOverflow() reused the current time whenever the second-of-day was
unchanged, discarding the new nano-of-second. Adding or subtracting nanos
that did not cross a second boundary therefore returned the original value:
LocalDateTime::parse('2000-01-01T12:34:56.5')->plusNanos(1);
// 2000-01-01T12:34:56.5 instead of 2000-01-01T12:34:56.500000001
The shortcut now also requires the nano-of-second to be unchanged.
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 #136 +/- ##
=========================================
Coverage 99.23% 99.23%
- Complexity 1139 1140 +1
=========================================
Files 48 48
Lines 2489 2491 +2
=========================================
+ Hits 2470 2472 +2
Misses 19 19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Member
|
Thank you, @gnutix! |
Member
|
Released as 0.10.4. |
Contributor
Author
|
Just so you know, it's totally okay for me if you don't release each bug fix "right away" :) If I ever have a bug fix that's urgent, I'll let you know (though I'll probably just fix it in my project with a composer patch first anyway 😄 ). Of course, your reactivity is much appreciated, and it makes it that much nicer to contribute back to this library. 🙏 |
Member
|
I usually prefer to not keep things unreleased, but I may group some of your upcoming fixes under the same release! 😉 |
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.
Problem
LocalDateTime::plusNanos()andminusNanos()return the original value when the result stays within the same second:plusWithOverflow()reuses the currentLocalTimewhenever the second-of-day is unchanged, which drops the newly computed nano-of-second. Java's original compares the nano-of-day instead. The existing test cases all cross a second boundary, so they did not catch it.The other callers (
plusHours(),plusMinutes(),plusSeconds()and theirminuscounterparts) pass zero nanos, so the shortcut was correct for them and they are unaffected.Change
The shortcut now also requires the nano-of-second to be unchanged. New test cases cover adding and subtracting nanos within the same second, including a whole-day jump where the second-of-day comes back equal.
🤖 Generated with Claude Code, Opus 5.5
https://claude.ai/code/session_01Fm9bvgKFasEGzpK48bQrxA