#date-time-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

#25 in #date-time-parser

Download history 91/week @ 2025-11-12 21/week @ 2025-11-19 4/week @ 2025-11-26 7/week @ 2025-12-03 2/week @ 2025-12-10 3/week @ 2025-12-17 2/week @ 2025-12-31 1/week @ 2026-01-07 1/week @ 2026-01-14 50/week @ 2026-01-21 122/week @ 2026-01-28 57/week @ 2026-02-04 142/week @ 2026-02-11 89/week @ 2026-02-18

436 downloads per month
Used in 3 crates (2 directly)

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

~56–340KB