use std::time::Duration;
pub fn format_elapsed_time(elapsed: Duration) -> String {
let total_secs = elapsed.as_secs();
if total_secs < 60 {
format!("{}s", total_secs)
} else if total_secs < 3600 {
let mins = total_secs / 60;
let secs = total_secs % 60;
if secs > 0 {
format!("{}m {}s", mins, secs)
} else {
format!("{}m", mins)
}
} else {
let hours = total_secs / 3600;
let mins = (total_secs % 3600) / 60;
let secs = total_secs % 60;
if mins > 0 && secs > 0 {
format!("{}h {}m {}s", hours, mins, secs)
} else if mins > 0 {
format!("{}h {}m", hours, mins)
} else if secs > 0 {
format!("{}h {}s", hours, secs)
} else {
format!("{}h", hours)
}
}
}