Show sync times as minutes and seconds
CI / integration (push) Successful in 19s
CI / test (push) Successful in 23s
CI / publish (push) Skipped
CI / docker (push) Successful in 46s

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 <noreply@anthropic.com>
This commit is contained in:
SansanandClaude Opus 5.5 committed 2026-10-15 22:07:02 +02:00
1 parent 439ffede18
commit 8da5468efb
2 files changed
+10 -4

No files matched your search

+6 -3
View File
@@ -45,12 +45,12 @@ type SyncResponse struct {
SoundtracksChangedContent []string `json:"soundtracks_changed_content"` SoundtracksChangedContent []string `json:"soundtracks_changed_content"`
SoundtracksRemoved []string `json:"soundtracks_removed"` SoundtracksRemoved []string `json:"soundtracks_removed"`
CatchedErrors []string `json:"catched_errors"` 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 { type ProgressResponse struct {
Progress string `json:"progress"` 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 type SoundtrackStatus int
@@ -164,8 +164,11 @@ func (s *SyncService) ResetDB(ctx context.Context) error {
return s.q.ClearSoundtracks(ctx) 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 { 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. // syncRun holds the state of a single sync.
+4 -1
View File
@@ -401,7 +401,10 @@ func TestResetDB(t *testing.T) {
} }
func TestFormatDuration(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) { func TestSyncKeepsAlternativeNamesAndCover(t *testing.T) {