Expand description
Nanosecond timestamp and duration types.
UnixNanos represents a timestamp since the UNIX epoch, while DurationNanos
represents an unsigned elapsed duration. Timestamp differences produce durations, and
timestamps accept durations for arithmetic so the two concepts cannot be mixed implicitly.
§Features
- Zero-cost abstraction with appropriate operator implementations.
- Conversion to/from
Timestampandstd::time::Duration. - RFC 3339 string formatting.
- Duration calculations.
- Flexible parsing and serialization.
§Parsing and Serialization
UnixNanos can be created from and serialized to various formats:
- Integer values are interpreted as nanoseconds since the UNIX epoch.
- Floating-point values are interpreted as seconds since the UNIX epoch (converted to nanoseconds
using truncation, not rounding, for consistency with
secs_to_nanos). - String values may be:
- A numeric string (interpreted as nanoseconds).
- A floating-point string (interpreted as seconds, converted to nanoseconds).
- An RFC 3339 formatted timestamp (ISO 8601 with timezone).
- A simple date string in YYYY-MM-DD format (interpreted as midnight UTC on that date).
§Limitations
- Negative timestamps are invalid and will result in an error.
- Arithmetic operations will panic on overflow/underflow rather than wrapping.
- The
as_i64()method will panic for timestamps beyond approximately year 2262 (when nanoseconds exceedi64::MAX).
Structs§
- Duration
Nanos - Represents an unsigned duration in nanoseconds.
- Duration
Nanos OutOf Range Error - Error returned when a duration cannot be represented as nanoseconds.
- Unix
Nanos - Represents a timestamp in nanoseconds since the UNIX epoch.