humantime

Function parse_duration

source
pub fn parse_duration(s: &str) -> Result<Duration, Error>
Expand description

Parse duration object 1hour 12min 5s

The duration object is a concatenation of time spans. Where each time span is an integer number and a suffix. Supported suffixes:

  • nsec, ns – nanoseconds
  • usec, us – microseconds
  • msec, ms – milliseconds
  • seconds, second, sec, s
  • minutes, minute, min, m
  • hours, hour, hr, h
  • days, day, d
  • weeks, week, w
  • months, month, M – defined as 30.44 days
  • years, year, y – defined as 365.25 days

§Examples

use std::time::Duration;
use humantime::parse_duration;

assert_eq!(parse_duration("2h 37min"), Ok(Duration::new(9420, 0)));
assert_eq!(parse_duration("32ms"), Ok(Duration::new(0, 32_000_000)));