Skip to main content

Crate pretty_ms

Crate pretty_ms 

Source
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-ms npm package. Construct with Options::default and the builder methods:

Functions§

pretty_duration
Format a Duration as a human-readable string. See pretty_ms.
pretty_ms
Convert milliseconds into a human-readable string.