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

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

#437 in Date and time

Download history 192/week @ 2024-07-22 68/week @ 2024-07-29 95/week @ 2024-08-05 85/week @ 2024-08-19 14/week @ 2024-08-26 33/week @ 2024-09-02 13/week @ 2024-09-09 3/week @ 2024-09-16 44/week @ 2024-09-23 35/week @ 2024-09-30 9/week @ 2024-10-07 20/week @ 2024-10-14 130/week @ 2024-10-28

161 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–320KB