package formatter import ( "testing" "time" ) func TestRelative(t *testing.T) { t.Parallel() now := time.Now() tests := []struct { name string t time.Time want string }{ {"just now", now.Add(-5 * time.Second), "just now"}, {"1 minute ago", now.Add(-1 * time.Minute), "1 minute ago"}, {"5 minutes ago", now.Add(-5 * time.Minute), "5 minutes ago"}, {"1 hour ago", now.Add(-1 * time.Hour), "1 hour ago"}, {"3 hours ago", now.Add(-3 * time.Hour), "3 hours ago"}, {"1 day ago", now.Add(-24 * time.Hour), "1 day ago"}, {"2 days ago", now.Add(-48 * time.Hour), "2 days ago"}, {"1 month ago", now.Add(-30 * 24 * time.Hour), "1 month ago"}, {"3 months ago", now.Add(-90 * 24 * time.Hour), "3 months ago"}, {"1 year ago", now.Add(-365 * 24 * time.Hour), "1 year ago"}, {"2 years ago", now.Add(-730 * 24 * time.Hour), "2 years ago"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { t.Parallel() got := Relative(tt.t) if got != tt.want { t.Errorf("Relative() = %q, want %q", got, tt.want) } }) } }