Skip to main content

parse_relative_duration

Function parse_relative_duration 

Source
pub fn parse_relative_duration(input: &str) -> Option<Duration>
Expand description

Parse a relative duration like 7d, 24h, 1w, 1m, 90s, 1y.

Calendar units (m, y) are imprecise; for windows we use these conventions:

  • s — seconds
  • min — minutes (use this rather than m to avoid the months-vs-minutes ambiguity)
  • h — hours
  • d — days
  • w — weeks (= 7 days)
  • mmonths (= 30 days; matches what most users mean by “1m” in analytics windows)
  • y — years (= 365 days)

For exact calendar math, pass an ISO-8601 timestamp instead.