From 71e066fe0dda49b146e21030c3925ecc3ba40e19 Mon Sep 17 00:00:00 2001 From: Jamie Banks Date: Mon, 8 Jun 2026 16:33:21 +0100 Subject: [PATCH] feat: add formatDuration helper and apply it to history dashboard processing times --- internal/web/server.go | 25 ++++++++++++++++++++++++- web/templates/history.html | 2 +- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/internal/web/server.go b/internal/web/server.go index ac75c38..9a83375 100644 --- a/internal/web/server.go +++ b/internal/web/server.go @@ -209,6 +209,28 @@ func formatBytes(bytes int64) string { return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp]) } +func formatDuration(seconds float64) string { + if seconds <= 0 { + return "0s" + } + + totalSecs := int64(seconds) + hours := totalSecs / 3600 + minutes := (totalSecs % 3600) / 60 + secs := totalSecs % 60 + + if hours > 0 { + return fmt.Sprintf("%dh %dm %ds", hours, minutes, secs) + } + if minutes > 0 { + return fmt.Sprintf("%dm %ds", minutes, secs) + } + if seconds < 1.0 { + return fmt.Sprintf("%.2fs", seconds) + } + return fmt.Sprintf("%.1fs", seconds) +} + func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) { if r.URL.Path != "/" { http.NotFound(w, r) @@ -309,7 +331,8 @@ func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) { } tmpl, err := template.New("layout").Funcs(template.FuncMap{ - "formatBytes": formatBytes, + "formatBytes": formatBytes, + "formatDuration": formatDuration, }).ParseFS(rootweb.FS, "templates/layout.html", "templates/history.html") if err != nil { http.Error(w, err.Error(), http.StatusInternalServerError) diff --git a/web/templates/history.html b/web/templates/history.html index cdb670d..53b8a32 100644 --- a/web/templates/history.html +++ b/web/templates/history.html @@ -44,7 +44,7 @@ {{formatBytes .OriginalSize}} {{formatBytes .EncodedSize}} {{formatBytes .SizeSaved}} - {{.ProcessingTime}}s + {{formatDuration .ProcessingTime}} {{.CreatedAt.Format "Jan 02, 15:04:05"}} {{else}}