Function apollo_framework::fmt::format_duration[][src]

pub fn format_duration(duration: Duration) -> String
Expand description

Formats a duration into a string like “5d 3h 17m 2s 12ms”.

As the format indicates this is mostly used for “shorter” durations which rather run in seconds or minutes rather than several days. However, if required, we can still format such a value, even if outputting milliseconds in this case is kind of questionable.

Also note that for formatting sort durations (in microseconds) we have a dedicated function named format_short_duration.

Examples

assert_eq!(apollo_framework::fmt::format_duration(Duration::from_millis(13)), "13ms");
assert_eq!(apollo_framework::fmt::format_duration(Duration::from_millis(1013)), "1s 13ms");
assert_eq!(apollo_framework::fmt::format_duration(Duration::from_millis(62_013)), "1m 2s 13ms");
assert_eq!(apollo_framework::fmt::format_duration(Duration::from_secs(60 * 32 + 13)), "32m 13s");
assert_eq!(apollo_framework::fmt::format_duration(Duration::from_secs(60 * 61)), "1h 1m");
assert_eq!(apollo_framework::fmt::format_duration(Duration::from_secs(4 * 60 * 60)), "4h");
assert_eq!(apollo_framework::fmt::format_duration(Duration::from_secs(24 * 60 * 60 + 60 * 60 + 60)), "1d 1h 1m");
assert_eq!(apollo_framework::fmt::format_duration(Duration::from_secs(24 * 60 * 60 + 60 * 60 + 59)), "1d 1h 59s");