#date-time-parser #duration #date-time #diff #time-parser #time #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

#643 in Date and time

Download history 3/week @ 2024-12-04 15/week @ 2024-12-11 1/week @ 2025-01-01 6/week @ 2025-02-05 12/week @ 2025-02-12 15/week @ 2025-02-26 80/week @ 2025-03-05 82/week @ 2025-03-12 68/week @ 2025-03-19

245 downloads per month
Used in render-cli

MIT license

10KB
166 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

~42–325KB