Expand description
relhu is a library that can parse relative and/or human time duration strings.
§Examples
use std::time::{Duration, Instant};
// Parsing to get a duration.
assert_eq!(relhu::parse_duration("5s").unwrap(), Duration::from_secs(5));
assert_eq!(relhu::parse_duration("100 us").unwrap(), Duration::from_micros(100));
// Parsing to get an instant in the future.
let now = Instant::now();
assert_eq!(relhu::parse_with_instant("15m later", now).unwrap(), now + Duration::from_secs(15 * 60));
assert_eq!(relhu::parse_with_instant("+55ms", now).unwrap(), now + Duration::from_millis(55));
// Parsing to get an instant in the past.
let now = Instant::now();
assert_eq!(relhu::parse_with_instant("20ns ago", now).unwrap(), now - Duration::from_nanos(20));
assert_eq!(relhu::parse_with_instant("- 5 days", now).unwrap(), now - Duration::from_secs(5 * 60 * 60 * 24));Enums§
- Error
- An error while parsing a relative human time duration string.
Functions§
- checked_
parse_ instant - Parse
inputas anInstant. If the input will result in overflow, it will returnNone. - checked_
parse_ with_ instant - Parse
inputas anInstant, based on a providedInstant. If the input will result in overflow, it will returnNone. - parse_
duration - Parse
inputas aDuration. - parse_
instant - Parse
inputas anInstant. - parse_
with_ instant - Parse
inputas anInstant, based on a providedInstant.