web: show track times in mm:ss (or h:mm:ss), matching the TUI

The now-playing clock rendered raw milliseconds as seconds, so a 3:04
track read as 3070:32. TrackPosition carries milliseconds (the TUI wraps
it with Duration::from_millis); convert ms to seconds at both display
sites. The progress gauge already used a position/duration ratio, so it
was unaffected. format_seconds now zero-pads minutes and rolls into
h:mm:ss past an hour, matching the TUI's now-playing pane.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Test User 2026-07-24 12:23:20 +02:00
parent 739c5a805a
commit c4001df74d
2 changed files with 17 additions and 6 deletions

View File

@ -1068,7 +1068,7 @@ fn Transport(store: Store) -> impl IntoView {
</span>
<div class="progress">
<span class="time">
{move || format_seconds(store.position.get().position)}
{move || format_seconds(store.position.get().position / 1000)}
</span>
<div class="gauge">
<div
@ -1088,7 +1088,7 @@ fn Transport(store: Store) -> impl IntoView {
></div>
</div>
<span class="time">
{move || format_seconds(store.position.get().duration)}
{move || format_seconds(store.position.get().duration / 1000)}
</span>
</div>
</div>

View File

@ -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");
}
}