Skip to content

API: Floor pre-epoch timestamps when converting to microseconds - #18116

Open
laserninja wants to merge 2 commits into
apache:mainfrom
laserninja:fix/pre-epoch-microsecond-conversion
Open

laserninja wants to merge 2 commits into
apache:mainfrom
laserninja:fix/pre-epoch-microsecond-conversion

Conversation

@laserninja

@laserninja laserninja commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Fixes #18115.

Parsing 1969-12-31T23:59:59.999999999 directly as a microsecond timestamp returns 0, 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 revapi checks passed. Coverage includes public literal conversion, offset handling, positive/exact-unit controls, both long boundaries, and overflow rejection.


AI Disclosure

  • Model: GPT-6
  • Platform/Tool: Codex
  • Human Oversight: reviewed
  • Prompt Summary: Reproduce and fix inconsistent pre-epoch timestamp conversion, add boundary regressions, and create an issue and PR.

Align Java temporal conversion with nanosecond precision reduction while retaining checked arithmetic across the full microsecond range.

Fixes apache#18115

Generated-by: Codex
@github-actions github-actions Bot added the API label Sep 15, 2026
@kevinjqliu

Copy link
Copy Markdown
Contributor

Human Oversight: unreviewed

Hi @laserninja, could you please review the PR first? This would be very helpful for other reviewers and maintainers.

@laserninja

Copy link
Copy Markdown
Contributor Author

@kevinjqliu, yes, I reviewed it. I asked codex to generate the description and missed the Oversight section. Thanks for checking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

API: Pre-epoch fractional timestamps convert inconsistently to microseconds

2 participants