Repository navigation
Epoch and Duration
pub struct Epoch { /* i64 seconds + u32 nanoseconds */ }An Epoch is a continuous TAI instant stored as whole seconds plus
nanoseconds since 2000-01-01T00:00:00 TAI. Because TAI has no leap
seconds, the value is monotonic and Ord is meaningful.
| Function | Behaviour |
|---|---|
Epoch::from_parts(sec, nanos) |
Normalises nanoseconds; panics on overflow |
Epoch::from_tai_seconds(f64) |
Panics on NaN, infinity or overflow |
Epoch::checked_from_parts |
Returns Option<Epoch> for untrusted input |
Epoch::checked_from_tai_seconds |
Returns Option<Epoch> for untrusted input |
The unchecked forms deliberately panic rather than wrap. A silent wrap at
i64::MAX would move an epoch by 585 billion years; failing loudly is the
only safe behaviour for a time library.
epoch.sec(); // i64 whole TAI seconds
epoch.nanos(); // u32, always < 1e9
epoch.tai_seconds(); // f64
epoch.checked_add(Duration);
epoch.checked_sub(Duration);Add/Sub with a Duration are available and panic on overflow; the
checked_* forms return Option.
pub struct Duration { /* i64 seconds + i32 nanoseconds, normalised */ }-
nanos()is always in0..1e9; the sign lives in the seconds field. -
total_nanoseconds()returnsi128and is exact for the whole domain. -
checked_neg,checked_add,checked_sub,checked_mul_i64all compute ini128and accept representable extrema, includinga - a = 0for the most negative value. -
floor(step),ceil(step)andround(step)work on timestamps with a grid step.
TimeSeries::inclusive(start, end, step);
TimeSeries::exclusive(start, end, step);- A zero or negative step yields an empty iterator rather than looping.
- The cursor uses checked addition, so the last representable epoch is delivered before iteration ends instead of overflowing.
- The series iterates
Epochvalues; format them through the conversions.
The nanosecond field makes the representation reversible and keeps UTC
fractions from being lost in f64. It does not claim nanosecond accuracy:
the accuracy of any result is bounded by the model and the data, as stated in
TDB models and Verification.
Every type on this page is available in no_std builds with alloc.
Arithmetic is integer-based; no floating-point accumulation is used for
Epoch or Duration. See no_std and embedded.
