Function duration_str::parse_std

source ·
pub fn parse_std(input: impl AsRef<str>) -> Result<Duration, String>
Expand description

convert Into<String> to std::time::Duration

§Example

use duration_str::parse;
use std::time::Duration;

// supports units
let duration = parse("1d").unwrap();
assert_eq!(duration,Duration::new(24*60*60,0));

// supports addition
let duration = parse("3m+31").unwrap();
assert_eq!(duration,Duration::new(211,0));

// spaces are optional
let duration = parse("3m + 31").unwrap();
assert_eq!(duration,Duration::new(211,0));

// plus sign is optional
let duration = parse("3m  31").unwrap();
assert_eq!(duration,Duration::new(211,0));

// both plus and spaces are optional
let duration = parse("3m31").unwrap();
assert_eq!(duration,Duration::new(211,0));

// supports multiplication
let duration = parse("1m*10").unwrap();
assert_eq!(duration,Duration::new(600,0));

// spaces are optional
let duration = parse("1m * 10").unwrap();
assert_eq!(duration,Duration::new(600,0));