#duration #time #date-time #time-parser #diff #parser

relativetime

🦀 Rust library for printing human readable, relative time differences

4 releases

0.1.4 May 17, 2022
0.1.3 May 17, 2022
0.1.1 May 17, 2022
0.1.0 May 17, 2022

#429 in Date and time

Download history 2/week @ 2024-01-16 2/week @ 2024-01-23 1/week @ 2024-02-13 40/week @ 2024-02-20 136/week @ 2024-02-27 16/week @ 2024-03-05 8/week @ 2024-03-12

164 downloads per month
Used in render-cli

MIT license

9KB
130 lines

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!

Dependencies

~39–325KB