Expand description
The single duration grammar for <number><unit> strings.
Every subsystem that accepts a human-written duration (“5m”, “200ms”, “1h”) parses it here, under one set of rules:
- A unit suffix is required.
"30"is an error, not an implicit millisecond count — a unitless number reads as seconds to most people and as milliseconds to most APIs, so guessing silently misreads it. - The vocabulary is
ms,s,m,h,d,w, matched case-insensitively, tolerating whitespace before the suffix. - Arithmetic is checked. An oversized value is reported, never clamped:
a timeout that silently becomes
u64::MAXpresents to the user as a hang, which is far harder to diagnose than a parse error.
These rules were previously three forked copies that disagreed. Most
sharply, when_budget.timeout was parsed by both the CLI manifest
validator and the runtime trigger_register, which disagreed on overflow —
the same string was rejected at validation but accepted and clamped at
registration. One grammar removes that class of divergence.
parse_millis owns the arithmetic and returns a structured
DurationParseError; each caller maps that onto its own error type and
wording, which stays the caller’s business.
The float/long-form cache-TTL parser (llm::cache) and the
OptionsParser millis path (stdlib::options, which rejects unit strings
outright) are deliberate outliers and do not use this module.
Enums§
- Duration
Parse Error - Why a duration string could not be interpreted.
Functions§
- parse_
millis - Parse a
<number><unit>duration string into milliseconds.