feat: add formatDuration helper and apply it to history dashboard processing times

This commit is contained in:
2026-06-08 16:33:21 +01:00
parent b58b861b7b
commit 71e066fe0d
2 changed files with 25 additions and 2 deletions
+23
View File
@@ -209,6 +209,28 @@ func formatBytes(bytes int64) string {
return fmt.Sprintf("%.1f %cB", float64(bytes)/float64(div), "KMGTPE"[exp]) 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) { func (s *Server) handleDashboard(w http.ResponseWriter, r *http.Request) {
if r.URL.Path != "/" { if r.URL.Path != "/" {
http.NotFound(w, r) http.NotFound(w, r)
@@ -310,6 +332,7 @@ func (s *Server) handleHistory(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.New("layout").Funcs(template.FuncMap{ tmpl, err := template.New("layout").Funcs(template.FuncMap{
"formatBytes": formatBytes, "formatBytes": formatBytes,
"formatDuration": formatDuration,
}).ParseFS(rootweb.FS, "templates/layout.html", "templates/history.html") }).ParseFS(rootweb.FS, "templates/layout.html", "templates/history.html")
if err != nil { if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError) http.Error(w, err.Error(), http.StatusInternalServerError)
+1 -1
View File
@@ -44,7 +44,7 @@
<td>{{formatBytes .OriginalSize}}</td> <td>{{formatBytes .OriginalSize}}</td>
<td>{{formatBytes .EncodedSize}}</td> <td>{{formatBytes .EncodedSize}}</td>
<td style="color: var(--accent);">{{formatBytes .SizeSaved}}</td> <td style="color: var(--accent);">{{formatBytes .SizeSaved}}</td>
<td>{{.ProcessingTime}}s</td> <td>{{formatDuration .ProcessingTime}}</td>
<td>{{.CreatedAt.Format "Jan 02, 15:04:05"}}</td> <td>{{.CreatedAt.Format "Jan 02, 15:04:05"}}</td>
</tr> </tr>
{{else}} {{else}}