Repository navigation
Fix nanosecond truncation in _pb_timestamp_to_datetime - #19265
Open
adityajai119 wants to merge 1 commit into
Open
adityajai119 wants to merge 1 commit into
adityajai119 wants to merge 1 commit into
Conversation
Contributor
There was a problem hiding this comment.
Code Review
This pull request modifies the _pb_timestamp_to_datetime helper function to use integer floor division (//) instead of float division (/) when converting nanoseconds to microseconds, ensuring nanoseconds are truncated rather than rounded. Corresponding unit tests have been added to verify this behavior. There are no review comments to address.
This branch has not been deployed
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.
@google-cloud/core's shared helper converted a
Timestamp's nanoseconds to microseconds with float division.datetime.timedeltathen rounded that float, so a timestamp withnanos=999999999became one full second past the epoch, andnanos=123456789became 123457 microseconds instead of 123456.This switches the conversion to integer floor division, matching the truncation already used when writing timestamps, so sub-second values are preserved and never overflow into the next second.
Added a regression test in
tests/unit/test__helpers.py. Narrow tests: 56 passed intest__helpers.py;ruff checkon both changed files passed.