use std::time::Duration;
pub const MIN_SECONDS_ONLY_TIME: Duration = Duration::from_secs(5);
pub fn duration_short(duration: impl Into<Duration>) -> String {
let duration = duration.into();
if duration >= MIN_SECONDS_ONLY_TIME {
humantime_seconds(duration)
} else {
humantime_milliseconds(duration)
}
}
pub fn humantime_seconds(duration: impl Into<Duration>) -> String {
let duration = duration.into();
let duration = Duration::from_secs(duration.as_secs());
let duration = humantime::format_duration(duration);
format!("{duration}")
}
pub fn humantime_milliseconds(duration: impl Into<Duration>) -> String {
let duration = duration.into();
let duration_secs = Duration::from_secs(duration.as_secs());
let duration_millis = Duration::from_millis(duration.subsec_millis().into());
let duration = humantime::format_duration(duration_secs + duration_millis);
format!("{duration}")
}