From 9f76b3ee3d4f50500ac2c2a03d84d74a4e624d59 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 05:14:43 +0000 Subject: [PATCH] fix(time): pluralize nil-service relative time fallback Co-Authored-By: Virgil --- time.go | 2 +- time_test.go | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) 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() -- 2.45.3