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.

```rust use relativetime::{RelativeTime, NegativeRelativeTime};

fn main() { let d = std::time::Duration::fromsecs(1); asserteq!(d.relativetime(), "in a few seconds"); asserteq!(d.relativetimein_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!