From 8da5468efb6ecbae036d0fd9bfd90f6dad18ace6 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Thu, 15 Oct 2026 22:07:02 +0200 Subject: [PATCH] Show sync times as minutes and seconds time_spent and total_time are now "MM:SS" instead of "HH:MM:SS". A sync longer than an hour keeps counting minutes, e.g. "62:03". Co-Authored-By: Claude Opus 5.5 --- internal/backend/sync.go | 9 ++++++--- internal/backend/sync_test.go | 5 ++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/internal/backend/sync.go b/internal/backend/sync.go index dcd9202..db5f339 100644 --- a/internal/backend/sync.go +++ b/internal/backend/sync.go @@ -45,12 +45,12 @@ type SyncResponse struct { SoundtracksChangedContent []string `json:"soundtracks_changed_content"` SoundtracksRemoved []string `json:"soundtracks_removed"` CatchedErrors []string `json:"catched_errors"` - TotalTime string `json:"total_time"` + TotalTime string `json:"total_time" doc:"How long the sync took, as minutes and seconds, e.g. \"02:15\""` } type ProgressResponse struct { Progress string `json:"progress"` - TimeSpent string `json:"time_spent"` + TimeSpent string `json:"time_spent" doc:"How long the sync has been running, as minutes and seconds, e.g. \"02:15\""` } type SoundtrackStatus int @@ -164,8 +164,11 @@ func (s *SyncService) ResetDB(ctx context.Context) error { return s.q.ClearSoundtracks(ctx) } +// formatDuration shows d as minutes and seconds, "MM:SS". A sync longer than an hour +// keeps counting minutes, e.g. "75:03". func formatDuration(d time.Duration) string { - return time.Time{}.Add(d).Format("15:04:05") + seconds := int(d / time.Second) + return fmt.Sprintf("%02d:%02d", seconds/60, seconds%60) } // syncRun holds the state of a single sync. diff --git a/internal/backend/sync_test.go b/internal/backend/sync_test.go index 090252d..30962d5 100644 --- a/internal/backend/sync_test.go +++ b/internal/backend/sync_test.go @@ -401,7 +401,10 @@ func TestResetDB(t *testing.T) { } func TestFormatDuration(t *testing.T) { - assert.Equal(t, "01:02:03", formatDuration(time.Hour+2*time.Minute+3*time.Second)) + assert.Equal(t, "00:00", formatDuration(0)) + assert.Equal(t, "00:07", formatDuration(7*time.Second+900*time.Millisecond), "parts of a second are left out") + assert.Equal(t, "02:15", formatDuration(2*time.Minute+15*time.Second)) + assert.Equal(t, "62:03", formatDuration(time.Hour+2*time.Minute+3*time.Second), "minutes keep counting past an hour") } func TestSyncKeepsAlternativeNamesAndCover(t *testing.T) {