relativetime

Crates.iorelativetime
lib.rsrelativetime
version0.1.4
sourcesrc
created_at2022-05-17 14:45:57.734801
updated_at2022-05-17 15:33:27.741021
description🦀 Rust library for printing human readable, relative time differences
homepagehttps://github.com/kurtbuilds/timediff
repositoryhttps://github.com/kurtbuilds/timediff
max_upload_size
id588370
size12,597
Kurt Wolf (kurtbuilds)

documentation

README

GitHub Contributors Stars Build Status Downloads Crates.io docs.rs

relativetime

relativetime provides traits on std::time::Duration and chrono::Duration to easily display human-readable relative times.

use relativetime::{RelativeTime, NegativeRelativeTime};


fn main() {
    let d = std::time::Duration::from_secs(1);
    assert_eq!(d.relative_time(), "in a few seconds");
    assert_eq!(d.relative_time_in_past(), "a few seconds ago");
    
    let d = chrono::Duration::from_secs(-1);
    assert_eq!(d.relative_time(), "a few seconds ago");
    let d = chrono::Duration::from_secs(1);
    assert_eq!(d.relative_time(), "in a few seconds");
}

See the docs for the API, and the tests for more example usage.

Contributing

Contributions are welcome!

Commit count: 0

cargo fmt