#duration #human #pretty

human-duration

human-duration converts a std::time::Duration to a human readable string

1 unstable release

0.1.0 Jan 17, 2022

#434 in Date and time

Download history 71/week @ 2024-07-28 71/week @ 2024-08-04 92/week @ 2024-08-11 55/week @ 2024-08-18 65/week @ 2024-08-25 58/week @ 2024-09-01 52/week @ 2024-09-08 50/week @ 2024-09-15 54/week @ 2024-09-22 67/week @ 2024-09-29 150/week @ 2024-10-06 93/week @ 2024-10-13 43/week @ 2024-10-20 40/week @ 2024-10-27 52/week @ 2024-11-03 34/week @ 2024-11-10

177 downloads per month
Used in 5 crates

MIT license

7KB
81 lines

human-duration

Crates.io Crates.io docs.rs

human-duration converts a std::time::Duration to a human readable string.

Examples

use human_duration::human_duration;

let duration = std::time::Duration::new(120, 30_000_000);
assert_eq!(human_duration(&duration), "2m 0s 30ms");

let duration = std::time::Duration::new(9000, 0);
assert_eq!(human_duration(&duration), "2h 30m 0s 0ms");

Usage

Run

cargo add human_duration

or manually add it to your Cargo.toml:

[dependencies]
human_duration = "0.1"

Then use the human_duration function:

use human_duration::human_duration;

// somewhere in your code:
let duration = std::time::Duration::new(120, 0);
println!(human_duration(&duration));

License

MIT


lib.rs:

Human-readable duration

human-duration converts a std::time::Duration to a human readable string.

Examples:

use human_duration::human_duration;

let duration = std::time::Duration::new(120, 30_000_000);
assert_eq!(human_duration(&duration), "2m 0s 30ms");

let duration = std::time::Duration::new(9000, 0);
assert_eq!(human_duration(&duration), "2h 30m 0s 0ms");

No runtime deps