| Crates.io | relativetime |
| lib.rs | relativetime |
| version | 0.1.4 |
| created_at | 2022-05-17 14:45:57.734801+00 |
| updated_at | 2022-05-17 15:33:27.741021+00 |
| description | 🦀 Rust library for printing human readable, relative time differences |
| homepage | https://github.com/kurtbuilds/timediff |
| repository | https://github.com/kurtbuilds/timediff |
| max_upload_size | |
| id | 588370 |
| size | 12,597 |
relativetimerelativetime 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.
Contributions are welcome!