Skip to content

Implement Ord trait for Timespec #4519

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
Jan 20, 2013
Merged

Implement Ord trait for Timespec #4519

merged 1 commit into from
Jan 20, 2013

Conversation

cpeterso
Copy link
Contributor

Note that Timespec does not perform any range checking and this change does not add any!

This implementation of Ord assumes that pre-epoch Timespecs have negative sec and positive nsec fields. Linux's and Darwin's struct timespec functions handle pre-epoch timestamps with this "two steps back, half step forward" representation, though I cannot find any documentation that actually puts this in writing. This means that (say) -1.2 seconds is represented by Timespec { sec: -2_i64, nsec: 800_000_000_i32 }, not something like Timespec { sec: -1_i64, nsec: -200_000_000_i32 } or Timespec { sec: -1_i64, nsec: 200_000_000_i32 }.

If we wish to codify this implementation detail, we could make Timespec nsec unsigned and add range checks asserting nsec <= 999_999_999_u32. btw, struct Tm also lacks range checking and uses signed integers for fields that can't be negative.

@cpeterso
Copy link
Contributor Author

I renamed the test_timespec_eq_org() function to test_timespec_eq_ord().

catamorphism added a commit that referenced this pull request Jan 20, 2013
@catamorphism catamorphism merged commit fa4f4fa into rust-lang:incoming Jan 20, 2013
@catamorphism
Copy link
Contributor

Great, thanks! May I suggest putting your comment above about the assumptions about negative and positive fields into a comment in the code? I don't really have opinions on this myself, but at least there'll be a note that's easy to find about what decisions got deferred.

@cpeterso cpeterso deleted the impl-timespec-ord branch January 21, 2013 07:15
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.

2 participants