Skip to content

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

Merged
merged 1 commit into from
Jun 11, 2021

Conversation

marcbowes
Copy link
Contributor

@marcbowes marcbowes commented Jun 10, 2021

Issue #, if available: #190

Description of changes:

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.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

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.
@marcbowes marcbowes requested a review from zslayton June 10, 2021 17:34
@codecov
Copy link

codecov bot commented Jun 10, 2021

Codecov Report

Merging #282 (4ecd608) into main (a23433a) will decrease coverage by 0.00%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/types/timestamp.rs 95.10% <100.00%> (-0.02%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update a23433a...4ecd608. Read the comment docs.

// 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(|| {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Note west -> east.

Comment on lines +686 to +687
let timestamp1 = builder.clone().build_at_offset(5 * 60)?;
let timestamp2 = builder.clone().build_at_offset(5 * 60)?;
Copy link
Contributor Author

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)
Copy link
Contributor Author

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.

Copy link
Contributor

@almann almann left a 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.

@almann almann linked an issue Jun 11, 2021 that may be closed by this pull request
Copy link
Contributor

@zslayton zslayton left a 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!

@marcbowes marcbowes merged commit 69dd3b4 into amazon-ion:main Jun 11, 2021
@marcbowes marcbowes deleted the build-at-offset branch June 11, 2021 17:08
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.

Timestamp Builder API Mismatch
3 participants