Expand description
§pretty-ms — human-readable milliseconds
Convert a millisecond count into a compact, human-readable string. A faithful
Rust port of the pretty-ms npm
package, with the same options (compact, verbose, colon notation, decimal
digits, sub-millisecond formatting, …). Zero dependencies.
use pretty_ms::{pretty_ms, Options};
assert_eq!(pretty_ms(1_337_000_000.0, &Options::default()), "15d 11h 23m 20s");
assert_eq!(pretty_ms(1337.0, &Options::default()), "1.3s");
assert_eq!(pretty_ms(1000.0, &Options::default().verbose(true)), "1 second");
assert_eq!(pretty_ms(95_500.0, &Options::default().colon_notation(true)), "1:35.5");A Duration convenience wrapper is also provided:
use std::time::Duration;
use pretty_ms::{pretty_duration, Options};
assert_eq!(pretty_duration(Duration::from_secs(90), &Options::default()), "1m 30s");Structs§
- Options
- Formatting options, mirroring the
pretty-msnpm package. Construct withOptions::defaultand the builder methods:
Functions§
- pretty_
duration - Format a
Durationas a human-readable string. Seepretty_ms. - pretty_
ms - Convert
millisecondsinto a human-readable string.