mozilla/rust — pull request #4519 by cpeterso (2013-01-17 07:44:02+00:00)
Title: Implement Ord trait for Timespec

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

This implementation of `Ord` assumes that pre-epoch `Timespec`s 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.