#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

#425 in Date and time

Download history 51/week @ 2024-11-16 55/week @ 2024-11-23 55/week @ 2024-11-30 82/week @ 2024-12-07 77/week @ 2024-12-14 27/week @ 2024-12-21 14/week @ 2024-12-28 47/week @ 2025-01-04 73/week @ 2025-01-11 62/week @ 2025-01-18 37/week @ 2025-01-25 65/week @ 2025-02-01 62/week @ 2025-02-08 51/week @ 2025-02-15 74/week @ 2025-02-22 33/week @ 2025-03-01

230 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