Skip to main content

Module duration

Module duration 

Source
Expand description

Short duration parsing for CLI flags like --admin-expires 7d, plus user-facing display helpers.

Internally we always store and transmit times as UTC unix-epoch seconds. Anything shown to the operator is converted to their local timezone for readability.

Duration parsing accepts N[s|m|h|d|w] — seconds, minutes, hours, days, weeks — or a plain integer which is interpreted as seconds. Whitespace is trimmed.

Functions§

duration_to_expires_at
Parse a duration and return the absolute unix-epoch expiry time (now + duration).
format_local_datetime
Format a DateTime<Utc> (the protocol-level wire format) as a readable local-timezone string with an ISO-style offset.
format_local_time
Format a unix-epoch seconds value as a readable local-timezone string with an ISO-style offset, suitable for operator-facing output.
format_remaining
Format a relative-time string showing how long until unix_secs from now_unix(). Handles both future (in 1h 0m) and past (expired 5m ago) cases. Picks the largest sensible unit pair and rounds toward the nearest integer in each.
humanize_duration
Format a duration in seconds as a compact two-part human string: “1h 30m”, “5d 12h”, “45s”, “0s”. Picks the largest unit that fits and adds one smaller unit when it helps readability.
now_unix
Current unix-epoch seconds (UTC, monotonic with the system wall clock).
parse_duration_secs
Parse a duration string into seconds.