#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

#27 in #date-time-parser

Download history 27/week @ 2025-10-21 3/week @ 2025-10-28 87/week @ 2025-11-11 23/week @ 2025-11-18 5/week @ 2025-11-25 8/week @ 2025-12-02 1/week @ 2025-12-09 3/week @ 2025-12-16 1/week @ 2025-12-23 1/week @ 2025-12-30 2/week @ 2026-01-06 1/week @ 2026-01-13 24/week @ 2026-01-20 126/week @ 2026-01-27 57/week @ 2026-02-03

208 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