Function duration_str::parse_time
source · pub fn parse_time(input: impl AsRef<str>) -> DResult<Duration>
Expand description
convert Into<String>
to time::Duration
§Example
use duration_str::parse_time;
use time::Duration;
// supports units
let duration = parse_time("1d").unwrap();
assert_eq!(duration,Duration::seconds(24*60*60));
// supports addition
let duration = parse_time("3m+31").unwrap();
assert_eq!(duration,Duration::seconds(211));
// spaces are optional
let duration = parse_time("3m + 31").unwrap();
assert_eq!(duration,Duration::seconds(211));
// plus sign is optional
let duration = parse_time("3m 31").unwrap();
assert_eq!(duration,Duration::seconds(211));
// both plus and spaces are optional
let duration = parse_time("3m31").unwrap();
assert_eq!(duration,Duration::seconds(211));
// supports multiplication
let duration = parse_time("1m*10").unwrap();
assert_eq!(duration,Duration::seconds(600));
// spaces are optional
let duration = parse_time("1m * 10").unwrap();
assert_eq!(duration,Duration::seconds(600));