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
161 downloads per month
Used in render-cli
9KB
130 lines
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