relhu

Crates.iorelhu
lib.rsrelhu
version
sourcesrc
created_at2025-03-30 07:38:32.576726+00
updated_at2025-03-30 07:43:44.410873+00
descriptionA library that can parse relative and/or human time duration strings.
homepage
repositoryhttps://github.com/ClementTsang/relhu
max_upload_size
id1612145
Cargo.toml error:TOML parse error at line 24, column 1 | 24 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include`
size0
Clement Tsang (ClementTsang)

documentation

https://docs.rs/relhu

README

relhu

relhu

relhu is a library that can parse relative and/or human time duration strings.

crates.io link Documentation

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.

Commit count: 0

cargo fmt