relhu 0.1.1

A library that can parse relative and/or human time duration strings.
Documentation
  • Coverage
  • 100%
    13 out of 13 items documented6 out of 6 items with examples
  • Size
  • Source code size: 44.17 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 770.29 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 6s Average build duration of successful builds.
  • all releases: 27s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • ClementTsang/relhu
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • ClementTsang

relhu

Usage

use std::time::{Duration, Instant};

fn main() {
    // 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));
}

Licensing

relhu is dual-licensed under MIT or Apache-2.0 at your choice.