#format-duration #duration-string #number-format #humanify-duration #easy-ready-duration

pretty-duration

Rust library that takes a duration and returns a string that is prettier to read for a human. The format of the duration can be customized in a short and long format and can be localized.

2 releases

0.1.1 Oct 28, 2022
0.1.0 Oct 28, 2022

#215 in Value formatting

Download history 126/week @ 2024-01-13 128/week @ 2024-01-20 357/week @ 2024-01-27 252/week @ 2024-02-03 254/week @ 2024-02-10 250/week @ 2024-02-17 181/week @ 2024-02-24 225/week @ 2024-03-02 114/week @ 2024-03-09 278/week @ 2024-03-16 248/week @ 2024-03-23 98/week @ 2024-03-30 144/week @ 2024-04-06 452/week @ 2024-04-13 157/week @ 2024-04-20 174/week @ 2024-04-27

936 downloads per month
Used in 4 crates

Apache-2.0

17KB
269 lines

Humanify Duration

github crates.io docs.rs build status codecov

Rust library that takes a duration and returns a string that is prettier to read for a human

Consumer of the Library

Install

cargo add pretty-duration

How to use?

use pretty_duration::pretty_duration;
use std::time::Duration;
let result = pretty_duration(&Duration::from_millis(1), None);

As a Developer of the Library

Tests

cargo test

Tests Coverage

You must install few components before running coverage:

cargo install grcov
rustup component add llvm-tools-preview

Then, you can run:

export RUSTFLAGS="-Cinstrument-coverage"
cargo build
export LLVM_PROFILE_FILE="profile-%p-%m.profraw"
cargo test
grcov . -s . --binary-path ./target/debug/ -t html --branch --ignore-not-existing -o ./target/debug/coverage/

Further explanation in the Mozilla grcov website

Documentation

cargo doc --open

Publishing

cargo login
cargo publish --dry-run
cargo publish

No runtime deps