API: Floor pre-epoch timestamps when converting to microseconds - #18116
Open
laserninja wants to merge 2 commits into
Open
laserninja wants to merge 2 commits into
laserninja wants to merge 2 commits into
Conversation
Align Java temporal conversion with nanosecond precision reduction while retaining checked arithmetic across the full microsecond range. Fixes apache#18115 Generated-by: Codex
Generated-by: Codex
1 task
Contributor
Hi @laserninja, could you please review the PR first? This would be very helpful for other reviewers and maintainers. |
Contributor
Author
|
@kevinjqliu, yes, I reviewed it. I asked codex to generate the description and missed the |
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.
Fixes #18115.
Parsing
1969-12-31T23:59:59.999999999directly as a microsecond timestamp returns0, while conversion through a nanosecond timestamp returns-1. Compute microseconds from epoch seconds and the fractional second, and share that conversion across Instant, LocalDateTime, and OffsetDateTime.Checked arithmetic preserves the full long microsecond range, including cases where a negative second's fractional part brings the result back into range.
Compatibility: pre-epoch inputs with a sub-microsecond remainder now floor one microsecond earlier than before, consistent with
nanosToMicros. This can change a derived date at a boundary. Exact-microsecond inputs and stored microsecond values are unchanged. Existing literal-conversion tests that explicitly expected the old behavior are updated.Maintainer decision requested: this changes behavior explicitly asserted by existing tests. Should direct microsecond conversion floor negative fractional inputs to match
nanosToMicros, or should truncation toward zero remain the compatibility contract? The alternative is to preserve the current conversion and document the discrepancy. No maintainer agreement or human review has been recorded yet.Validation on JDK 17: the new regressions failed before the fix; the full API test suite, API formatting/checkstyle, and API
revapichecks passed. Coverage includes public literal conversion, offset handling, positive/exact-unit controls, both long boundaries, and overflow rejection.AI Disclosure