Skip to content

Implement Ord trait for Timespec #4505

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

Closed
wants to merge 6 commits into from
Closed

Implement Ord trait for Timespec #4505

wants to merge 6 commits into from

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 cpeterso closed this Jan 17, 2013
@cpeterso cpeterso reopened this Jan 17, 2013
@cpeterso cpeterso closed this Jan 17, 2013
RalfJung added a commit to RalfJung/rust that referenced this pull request Aug 19, 2025
Use GH app for authenticating pull PRs
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.

4 participants