Skip to main content

parse_duration

Function parse_duration 

Source
pub fn parse_duration(s: &str) -> Option<DurationParts>
Expand description

Parses an ISO-8601 duration string (P[nY][nM][nW][nD][T[nH][nM][nS]], each n an optional-sign decimal) into raw DurationFields, then normalizes the same way duration({...}) does – construction from text and from a map are the same operation once the units are pulled apart, see normalize_duration’s docs.

Deliberately does not handle the alternative “combined date-time” duration representation (P2012-02-02T14:37:21.545, ISO-8601’s other duration syntax) – a real gap (see the README), not a silent misparse: that string doesn’t match P followed by number+letter pairs, so this returns None, the same “reject, don’t guess” outcome parse_date gives an unsupported date string form.