relativetime 0.1.4

🦀 Rust library for printing human readable, relative time differences
Documentation

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!