eternity-rs

Crates.ioeternity-rs
lib.rseternity-rs
version0.2.0
sourcesrc
created_at2023-08-23 01:09:12.285066
updated_at2023-08-23 23:42:02.605011
descriptionHuman and bot readable durations
homepage
repositoryhttps://github.com/hiteshjasani/eternity-rs
max_upload_size
id951480
size21,417
Hitesh Jasani (hiteshjasani)

documentation

README

eternity-rs

Answering the question, "how long did that take?", formattable to be readable by humans and bots.

Motivation

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.

Simple Example

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
Commit count: 12

cargo fmt