Crates.io | eternity-rs |
lib.rs | eternity-rs |
version | 0.2.0 |
source | src |
created_at | 2023-08-23 01:09:12.285066 |
updated_at | 2023-08-23 23:42:02.605011 |
description | Human and bot readable durations |
homepage | |
repository | https://github.com/hiteshjasani/eternity-rs |
max_upload_size | |
id | 951480 |
size | 21,417 |
Answering the question, "how long did that take?", formattable to be readable by humans and bots.
Rust does not implement Display
for std::time::Duration
. But even if it did, there wouldn't be a format that would be usable across the board. Formats that are human readable are hard to parse for bots, and vice versa. This crate provides extension traits to enable formatting durations for most cases.
use std::time::Duration;
use eternity_rs::Eternity;
let duration = Duration::from_secs(3672);
println!("{}", &duration.humanize());
=> 1h 1m 12s
println!("{}", &duration.robotize());
=> 0d 1h 1m 12s 0ms
let duration = Duration::from_secs(3622);
println!("{}", &duration.humanize());
=> 1h 22s
println!("{}", &duration.robotize());
=> 0d 1h 0m 22s 0ms
let duration = Duration::from_secs(127);
println!("{}", &duration.humanize());
=> 2m 7s
println!("{}", &duration.robotize());
=> 0d 0h 2m 7s 0ms