fix(wkt): non-negative timestamp nanos#1634
Merged
coryan merged 3 commits intogoogleapis:mainfrom Mar 27, 2025
Merged
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1634 +/- ##
=======================================
Coverage 95.71% 95.72%
=======================================
Files 43 43
Lines 1822 1824 +2
=======================================
+ Hits 1744 1746 +2
Misses 78 78 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The timestamp nanos are supposed to be non-negative. For timestamps before the epoch: > Negative second values with fractions must still have non-negative > nanos values that count forward in time. I took the opportunity to add some missing test cases.
118e8b0 to
bbb2448
Compare
dbolduc
approved these changes
Mar 27, 2025
src/wkt/src/timestamp.rs
Outdated
| let nanos_since_epoch = odt.unix_timestamp_nanos(); | ||
| let seconds = (nanos_since_epoch / NS) as i64; | ||
| let nanos = (nanos_since_epoch % NS) as i32; | ||
| if !(0..Self::NS).contains(&nanos) { |
Member
There was a problem hiding this comment.
if nanos < 0 might be more clear?
| let seconds = (nanos_since_epoch / NS) as i64; | ||
| let nanos = (nanos_since_epoch % NS) as i32; | ||
| if !(0..Self::NS).contains(&nanos) { | ||
| return Timestamp::new(seconds - 1, Self::NS + nanos); |
Member
There was a problem hiding this comment.
nit: Self::NS is just called NS above.
Member
There was a problem hiding this comment.
Oh, they are different types. Ignore me.
Collaborator
Author
There was a problem hiding this comment.
I got confused myself.
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.
The timestamp nanos are supposed to be non-negative. For timestamps
before the epoch:
I took the opportunity to add some missing test cases.