diff --git a/cbd-web/src/app.rs b/cbd-web/src/app.rs
index 6c736cb..e26d1ab 100644
--- a/cbd-web/src/app.rs
+++ b/cbd-web/src/app.rs
@@ -1068,7 +1068,7 @@ fn Transport(store: Store) -> impl IntoView {
- {move || format_seconds(store.position.get().position)}
+ {move || format_seconds(store.position.get().position / 1000)}
- {move || format_seconds(store.position.get().duration)}
+ {move || format_seconds(store.position.get().duration / 1000)}
diff --git a/cbd-web/src/state.rs b/cbd-web/src/state.rs
index 1d89920..7072684 100644
--- a/cbd-web/src/state.rs
+++ b/cbd-web/src/state.rs
@@ -345,9 +345,17 @@ impl CaptureBoard {
}
}
-/// `mm:ss` for progress and duration displays.
+/// `mm:ss`, or `h:mm:ss` once past an hour — matching the TUI's now-playing
+/// clock so minutes zero-pad and roll into hours instead of counting past 60.
pub fn format_seconds(total: u32) -> String {
- format!("{}:{:02}", total / 60, total % 60)
+ let secs = total % 60;
+ let mins = (total / 60) % 60;
+ let hours = total / 3600;
+ if hours > 0 {
+ format!("{hours}:{mins:02}:{secs:02}")
+ } else {
+ format!("{mins:02}:{secs:02}")
+ }
}
/// The now-playing line for a track, `artist - title` falling back to
@@ -529,8 +537,11 @@ mod tests {
#[test]
fn time_formatting_is_mm_ss() {
- assert_eq!(format_seconds(0), "0:00");
- assert_eq!(format_seconds(61), "1:01");
+ assert_eq!(format_seconds(0), "00:00");
+ assert_eq!(format_seconds(61), "01:01");
assert_eq!(format_seconds(3599), "59:59");
+ // Past an hour it rolls into h:mm:ss instead of counting past 60 min.
+ assert_eq!(format_seconds(3600), "1:00:00");
+ assert_eq!(format_seconds(3661), "1:01:01");
}
}