Skip to content

fix(java-core): preserve SQL timestamps just before the epoch - #14948

Open
Vcode2407 wants to merge 1 commit into
googleapis:mainfrom
Vcode2407:fix/sql-timestamp-before-epoch
Open

Vcode2407 wants to merge 1 commit into
googleapis:mainfrom
Vcode2407:fix/sql-timestamp-before-epoch

Conversation

@Vcode2407

Copy link
Copy Markdown

Converting a SQL timestamp in the last second before the Unix epoch currently moves it one second forward. For example, 1969-12-31T23:59:59.999999999Z becomes 1970-01-01T00:00:00.999999999Z.

This change uses Math.floorDiv to round the milliseconds down to whole seconds and keeps the original nanoseconds. The new regression test covers one nanosecond before the epoch. It failed on main and passed with the fix, along with all 222 google-cloud-core tests.

Fixes #14636

Round epoch milliseconds down to whole seconds before combining them with the original nanosecond fraction.

Fixes googleapis#14636
@Vcode2407
Vcode2407 requested a review from a team as a code owner November 9, 2026 13:10
@google-cla

google-cla Bot commented Nov 9, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request simplifies the timestamp conversion logic in Timestamp.of(java.sql.Timestamp) by replacing custom pre-epoch adjustment logic with Math.floorDiv. It also adds a unit test testOf_justBeforeEpoch to verify the correctness of the conversion for timestamps immediately preceding the epoch. There are no review comments, and I have no feedback to provide.

@Vcode2407

Copy link
Copy Markdown
Author

I signed the Google Individual CLA, but the rescan link returned HTTP 400 and GitHub still shows the original failed check. Could a Google maintainer please rescan the CLA for this PR? Thanks!

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[java-core] Timestamp.of(java.sql.Timestamp) is one second late for a time less than a second before the epoch

1 participant