3 releases

0.0.3 Jun 7, 2023
0.0.2 Dec 2, 2021
0.0.1 Aug 19, 2021

#267 in Value formatting

GPL-3.0-or-later

15KB
107 lines

htime

DEPRECATED

Please use the humantime crate instead.


lib.rs:

htime is a crate to provide convenient human-centric time formatting.

Examples

Given a Duration, generate a legible human output:

// One year minus 1 millisecond (demonstrates all the units).
let dur = std::time::Duration::from_millis(31_557_600_000 - 1);

// Prints the output as a nicely formatted string, with units in descending
// order of size. Specify the degree of unit precision desired as the second
// argument.
assert_eq!(
    htime::pretty_print(&dur, "ms", ", "),
    "11mo, 4w, 2d, 10h, 29m, 59s, 999ms",
)

Alternatively, you can just get back the list of value/unit strings, and arrange them yourself:


// Returns a list of the units, with no whitespace or separators.
assert_eq!(
    htime::components(&dur, "ms"),
    vec!["11mo", "4w", "2d", "10h", "29m", "59s", "999ms"],
)

No runtime deps