pub fn pretty_duration(
duration: &Duration,
options: Option<PrettyDurationOptions>,
) -> StringExpand description
Main function of the pretty-duration library that takes a required std::time::Duration and and optional PrettyDurationOptions.
§Arguments
The first argument is a std::time::Duration that is the input to produce the String output.
The second argument is the optional configuration PrettyDurationOptions giving you the possibility to decide the format (extended or compact) but also to decide the symbol and word for each PrettyDurationLabels
§Default
With an option set to None, the function returns the duration in a compact format in US English symbol.
§Examples
§No option outputs a string in a short format
use std::time::Duration;
use pretty_duration::pretty_duration;
let result = pretty_duration(&Duration::from_millis(1), None);
assert_eq!(result, "1ms");§Option to have the extended long format
use pretty_duration::pretty_duration;
use pretty_duration::PrettyDurationLabels;
use pretty_duration::PrettyDurationOptions;
use pretty_duration::PrettyDurationOutputFormat;
use std::time::Duration;
let result = pretty_duration(
&Duration::from_millis(43556556722),
Some(PrettyDurationOptions {
output_format: Some(PrettyDurationOutputFormat::Expanded),
singular_labels: None,
plural_labels: None,
}),
);
assert_eq!(
result,
"1 year 16 months 248 days 3 hours 2 minutes 36 seconds 722 milliseconds"
);