Skip to content

libtime: Use Duration in Timespec arithmetic. #16650

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
Aug 31, 2014

Conversation

ruuda
Copy link
Contributor

@ruuda ruuda commented Aug 21, 2014

This changes the Add and Sub implementations for Timespec introduced in #16573 to use Duration as the time span type instead of Timespec itself, as suggested by @sfackler.

This depends on #16626, because is uses Duration::seconds(i64), whereas currently Duration::seconds takes an i32.

@alexcrichton
Copy link
Member

This looks great, thanks! It may take #16626 more time to land than this, so perhaps this could be rebased on master and this could land first?

@ruuda ruuda force-pushed the timespec-arithmetic branch from 7df21fa to 913f0ff Compare August 22, 2014 06:36
@ruuda
Copy link
Contributor Author

ruuda commented Aug 22, 2014

This works with the current Duration. It’ll overflow for timespecs more than about 68 years apart.

// more than one second left, which fits in i64 in i32.
// FIXME: Construct duration from i64 to avoid overflow.
let d_nsec = (other - Duration::seconds(d_sec as i32))
.num_nanoseconds().unwrap() as i32;
Copy link
Member

Choose a reason for hiding this comment

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

Could you align this .num_nanoseconds() to the right to not be left-aligned?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wondered about that, what the best style is (I could not find anything in the style guide). Do you mean aligning it with the opening parenthesis?

@ruuda ruuda force-pushed the timespec-arithmetic branch from 913f0ff to cb8389d Compare August 25, 2014 20:58
@alexcrichton
Copy link
Member

Now that #16626 has been approve, this should probably wait to get merged, other than that this looks good to me!

@alexcrichton
Copy link
Member

Now that #16626 has merged, should this be rebased to remove the FIXMEs?

@ruuda
Copy link
Contributor Author

ruuda commented Aug 29, 2014

Yes, I’m running make check at the moment.

@ruuda ruuda force-pushed the timespec-arithmetic branch from cb8389d to d20de6d Compare August 29, 2014 18:16
bors added a commit that referenced this pull request Aug 31, 2014
This changes the `Add` and `Sub` implementations for `Timespec` introduced in #16573 to use `Duration` as the time span type instead of `Timespec` itself, as [suggested](#16573 (comment)) by @sfackler.

This depends on #16626, because is uses `Duration::seconds(i64)`, whereas currently `Duration::seconds` takes an `i32`.
@bors bors closed this Aug 31, 2014
@bors bors merged commit d20de6d into rust-lang:master Aug 31, 2014
bors added a commit to rust-lang-ci/rust that referenced this pull request Feb 25, 2024
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.

3 participants