diff --git a/controller/internal/web/funcmap.go b/controller/internal/web/funcmap.go index a1735c0..e64f082 100644 --- a/controller/internal/web/funcmap.go +++ b/controller/internal/web/funcmap.go @@ -229,6 +229,29 @@ func (s *Server) templateFuncMap() template.FuncMap { return fmt.Sprintf("%d napja", int(d.Hours()/24)) } }, + // timeAgoStr is timeAgo for RFC3339 string timestamps (e.g. OffboxTarget.LastRun, + // which persists as a string in settings.json). Found during D0: the backups page + // passed the raw string to timeAgo and 500'd once an off-box backup had ever run. + "timeAgoStr": func(s string) string { + t, err := time.Parse(time.RFC3339, s) + if err != nil { + return s + } + now := time.Now().In(loc) + d := now.Sub(t.In(loc)) + switch { + case d < time.Minute: + return "most" + case d < time.Hour: + return fmt.Sprintf("%d perce", int(d.Minutes())) + case d < 24*time.Hour: + return fmt.Sprintf("%d órája", int(d.Hours())) + case d < 48*time.Hour: + return "tegnap" + default: + return fmt.Sprintf("%d napja", int(d.Hours()/24)) + } + }, "fmtTime": func(t time.Time) string { if t.IsZero() { return "–" diff --git a/controller/internal/web/templates/backups.html b/controller/internal/web/templates/backups.html index 30cb4b8..7734cb2 100644 --- a/controller/internal/web/templates/backups.html +++ b/controller/internal/web/templates/backups.html @@ -123,9 +123,9 @@
Utolsó hiba: {{.Offbox.LastError}}
{{end}} + {{if .Offbox.LastError}}Utolsó hiba: {{.Offbox.LastError}}
{{end}} {{if .OffboxConfigured}}