diff --git a/frontend/src/components/torrent/table.rs b/frontend/src/components/torrent/table.rs index 6489685..6bbcd12 100644 --- a/frontend/src/components/torrent/table.rs +++ b/frontend/src/components/torrent/table.rs @@ -22,6 +22,27 @@ fn format_speed(bytes_per_sec: i64) -> String { format!("{}/s", format_bytes(bytes_per_sec)) } +fn format_duration(seconds: i64) -> String { + if seconds <= 0 { + return "∞".to_string(); + } + + let days = seconds / 86400; + let hours = (seconds % 86400) / 3600; + let minutes = (seconds % 3600) / 60; + let secs = seconds % 60; + + if days > 0 { + format!("{}d {}h", days, hours) + } else if hours > 0 { + format!("{}h {}m", hours, minutes) + } else if minutes > 0 { + format!("{}m {}s", minutes, secs) + } else { + format!("{}s", secs) + } +} + #[derive(Clone, Copy, Debug, PartialEq, Eq)] enum SortColumn { Name, @@ -273,7 +294,7 @@ pub fn TorrentTable() -> impl IntoView { {status_str} {format_speed(t.down_rate)} {format_speed(t.up_rate)} - {if t.eta > 0 { format!("{}s", t.eta) } else { "∞".to_string() }} + {format_duration(t.eta)} } }).collect::>()} @@ -460,7 +481,7 @@ pub fn TorrentTable() -> impl IntoView {
"ETA" - {if t.eta > 0 { format!("{}s", t.eta) } else { "∞".to_string() }} + {format_duration(t.eta)}