-
Notifications
You must be signed in to change notification settings - Fork 38
Clarify TimestampBuilder.build_at_offset #282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Before this commit, `TimestampBuilder.build_at_offset` claimed to take minutes but actually took "seconds west of UTC". Now, we take "minutes east of UTC" which is more inline with both intuition (at least, my own!) and how Ion represents the value in binary. Note that the `Timestamp` type uses the chrono types internally (such as an offset in seconds). This creates some annoying multiply/divide by 60. However, given that Ion doesn't actually support representing offset in seconds, it feels right to me to use minutes in our API. Maybe, in future work, we should more clearly restrict offsets to minutes and not use the chrono type. Fixes amazon-ion#190.
Codecov Report
@@ Coverage Diff @@
## main #282 +/- ##
==========================================
- Coverage 91.78% 91.78% -0.01%
==========================================
Files 56 56
Lines 8287 8285 -2
==========================================
- Hits 7606 7604 -2
Misses 681 681
Continue to review full report at Codecov.
|
// Our builder stores the offset in minutes difference from UTC. | ||
// We're about to convert to the chrono type which uses seconds. | ||
// Both values consider positive to mean Eastern Hemisphere. | ||
let offset = FixedOffset::east_opt(offset * 60).ok_or_else(|| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note west -> east.
let timestamp1 = builder.clone().build_at_offset(5 * 60)?; | ||
let timestamp2 = builder.clone().build_at_offset(5 * 60)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All these tests lost a minutes -> seconds conversion.
@@ -1012,7 +1014,7 @@ mod ionc_tests { | |||
), | |||
Timestamp::with_ymd(2020, 1, 1) | |||
.with_hour_and_minute(0, 1) | |||
.build_at_offset(8 * 60 * 60) | |||
.build_at_offset(-8 * 60) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This (and the next) test needed a sign update.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks right to me, thanks for doing it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, thanks for taking care of this!
Issue #, if available: #190
Description of changes:
Before this commit,
TimestampBuilder.build_at_offset
claimed to takeminutes but actually took "seconds west of UTC". Now, we take "minutes
east of UTC" which is more inline with both intuition (at least, my
own!) and how Ion represents the value in binary.
Note that the
Timestamp
type uses the chrono types internally (such asan offset in seconds). This creates some annoying multiply/divide by 60.
However, given that Ion doesn't actually support representing offset in
seconds, it feels right to me to use minutes in our API. Maybe, in
future work, we should more clearly restrict offsets to minutes and not
use the chrono type.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.