Function parse

Source
pub fn parse(source: &str) -> Result<Duration, ParseError>
Expand description

Parse the source string into a Duration

Any leading and trailing whitespace is ignored. The parser saturates at the maximum of Duration::MAX.

This method is equivalent to RelativeTimeParser::parse. See also the documentation of RelativeTimeParser::parse.

§Errors

Returns a ParseError if an error during the parsing process occurred

§Examples

use fundu_gnu::{parse, Duration};

assert_eq!(parse("2hours"), Ok(Duration::positive(2 * 60 * 60, 0)));
assert_eq!(parse("12 seconds"), Ok(Duration::positive(12, 0)));
assert_eq!(parse("123456789"), Ok(Duration::positive(123_456_789, 0)));
assert_eq!(parse("yesterday"), Ok(Duration::negative(24 * 60 * 60, 0)));