Expand description
A UnixNanos
type for working with timestamps in nanoseconds since the UNIX epoch.
This module provides a strongly-typed representation of timestamps as nanoseconds
since the UNIX epoch (January 1, 1970, 00:00:00 UTC). The UnixNanos
type offers
conversion utilities, arithmetic operations, and comparison methods.
§Features
- Zero-cost abstraction with appropriate operator implementations.
- Conversion to/from
DateTime<Utc>
. - 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).
- 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.
Structs§
- Unix
Nanos - Represents a timestamp in nanoseconds since the UNIX epoch.
Type Aliases§
- Duration
Nanos - Represents a duration in nanoseconds.