diff --git a/time.go b/time.go index 591b49e..62b49aa 100644 --- a/time.go +++ b/time.go @@ -43,7 +43,7 @@ func FormatAgo(count int, unit string) string { svc := Default() unit = normalizeAgoUnit(unit) if svc == nil { - return core.Sprintf("%d %ss ago", count, unit) + return core.Sprintf("%d %s ago", count, Pluralize(unit, count)) } key := "time.ago." + unit result := svc.T(key, map[string]any{"Count": count}) diff --git a/time_test.go b/time_test.go index 46c8519..e9ccc4a 100644 --- a/time_test.go +++ b/time_test.go @@ -192,6 +192,20 @@ func TestFormatAgo_Good_SingularUnit(t *testing.T) { assert.Equal(t, "1 fortnight ago", got) } +func TestFormatAgo_Good_NoDefaultService(t *testing.T) { + prev := Default() + SetDefault(nil) + t.Cleanup(func() { + SetDefault(prev) + }) + + got := FormatAgo(1, "second") + assert.Equal(t, "1 second ago", got) + + got = FormatAgo(5, "second") + assert.Equal(t, "5 seconds ago", got) +} + func TestFormatAgo_Good_FrenchRelativeTime(t *testing.T) { prev := Default() svc, err := New()