Expand description
Exact-precision duration container.
ExactDuration is the canonical duration type for tempoch. Its
representation is deliberately opaque: today it is backed by a single
i128 of nanoseconds (range ≈ ±5.4 × 10²¹ yr at 1 ns resolution). A future
internal migration to i128 attoseconds or another sub-nanosecond
representation is a non-breaking change as long as callers go through the
named accessors (as_seconds_i64_nanos, as_seconds_f64, …).
§Design choices
- Sign convention — a single signed integer carries the sign uniformly.
This avoids the classic
{whole_seconds: i64, sub_nanos: u32}pitfall where-0.5 smust be represented as{-1, 500_000_000}and negation becomes asymmetric near zero. - No
f64in the public exact API —f64boundaries are reachable only through explicitly named methods (from_seconds_f64_lossy,as_seconds_f64) so users see the lossy step in code review. - qtty interop —
ExactDuration::from_quantity/ExactDuration::as_quantitybridge to typedQuantity<U>for anyqtty::time::TimeUnit. The bridge throughf64is intentional:qttyitself is a floating-point quantity system; users wanting exact duration math should keep values insideExactDuration. - Overflow — arithmetic uses checked operations and reports
DurationError::Overflowwhen the result leaves the i128 range; the public+/-operators panic on overflow (debug + release) to matchDuration/std::timeergonomics. UseExactDuration::checked_add/ExactDuration::checked_sub/ExactDuration::checked_negfor non-panicking callers (FFI, parsers, formal-verification harnesses).
§Future-proofing
Because the storage is opaque and the boundary projection
(seconds: i64, nanos: u32) is the only serde shape, migrating to a
sub-nanosecond representation is non-breaking; callers requesting
attosecond precision in serde will opt in through a future
serde-attos feature.
Structs§
- Exact
Duration - Exact-precision signed duration.
Enums§
- Duration
Error - Error type for fallible
ExactDurationoperations.
Constants§
- NANOS_
PER_ SECOND - Nanoseconds per second; convenience constant for boundary code.