fix: human readable timestamps

This commit is contained in:
2026-02-21 00:20:32 +01:00
parent acab4333a7
commit 41a12fe7a9
+29 -1
View File
@@ -5,6 +5,7 @@ import (
"fmt"
"os"
"strings"
"time"
"git.jnss.me/joakim/opal/internal/engine"
"git.jnss.me/joakim/opal/internal/sync"
@@ -471,5 +472,32 @@ func getLocalChanges(since int64) ([]*engine.Task, error) {
}
func formatTimestamp(ts int64) string {
return fmt.Sprintf("%d", ts) // Simple for now, can enhance later
t := time.Unix(ts, 0)
now := time.Now()
diff := now.Sub(t)
switch {
case diff < time.Minute:
return "just now"
case diff < time.Hour:
m := int(diff.Minutes())
if m == 1 {
return "1 minute ago"
}
return fmt.Sprintf("%d minutes ago", m)
case diff < 24*time.Hour:
h := int(diff.Hours())
if h == 1 {
return "1 hour ago"
}
return fmt.Sprintf("%d hours ago", h)
case diff < 7*24*time.Hour:
d := int(diff.Hours() / 24)
if d == 1 {
return "yesterday"
}
return fmt.Sprintf("%d days ago", d)
default:
return t.Format("2006-01-02 15:04")
}
}