Expand description
The wire format for durations.
Durations are exchanged as part of the
x-sn-expiration header, for instance as ttl:7d 12h.
§Emitted format
A duration is written as a space-separated list of <integer><unit> components, ordered from
the largest unit to the smallest. Components that are zero are omitted, and a zero duration is
written as 0s. Only four units are ever emitted:
| Unit | Meaning |
|---|---|
d | day, 24 hours |
h | hour |
m | minute |
s | second |
Day is deliberately the largest unit. Weeks, months, and years are never emitted, because they
either have no fixed length (a calendar month) or invite a definition that differs between
implementations (is a year 365 or 365.25 days?). Durations longer than a day therefore stay in
days: 400 days is written as 400d, never as 1y 1m 5d.
Second is the smallest unit; any sub-second remainder is truncated.
§Parsing
parse_duration accepts a superset of the emitted format, including units this crate never
writes. That leniency exists to keep reading values that older versions persisted, and is not
part of the wire format: do not rely on it, and do not reproduce it in clients.
Structs§
- Formatted
Duration - A
Durationthat displays in the wire format. - Parse
Duration Error - The error returned when a string is not a valid duration in the wire format.
Functions§
- format_
duration - Formats a duration in the wire format.
- parse_
duration - Parses a duration from the wire format.