diff --git a/opal-task/cmd/sync.go b/opal-task/cmd/sync.go index 2005647..a44c4d2 100644 --- a/opal-task/cmd/sync.go +++ b/opal-task/cmd/sync.go @@ -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") + } }