use std::time::Duration;
#[must_use]
pub fn format(duration: Duration) -> String {
let secs = duration.as_secs();
let parts = [
(secs / 86_400, "d"),
(secs % 86_400 / 3600, "h"),
(secs % 3600 / 60, "m"),
(secs % 60, "s"),
(u64::from(duration.subsec_millis()), "ms"),
];
let text = parts
.iter()
.filter(|(amount, _)| *amount > 0)
.map(|(amount, unit)| std::format!("{amount}{unit}"))
.collect::<Vec<_>>()
.join(" ");
if text.is_empty() {
"0s".to_string()
} else {
text
}
}
#[cfg(test)]
#[path = "format.test.rs"]
mod tests;
#[cfg(test)]
#[path = "format.spec.rs"]
mod spec;