From ff42b06ae4c18e1e8050a47ebcdf8c5232b55238 Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 07:14:13 +0000 Subject: [PATCH] fix(time): normalise relative-time unit input Co-Authored-By: Virgil --- time.go | 1 + time_test.go | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/time.go b/time.go index 62b49aa..6d430b2 100644 --- a/time.go +++ b/time.go @@ -54,6 +54,7 @@ func FormatAgo(count int, unit string) string { } func normalizeAgoUnit(unit string) string { + unit = core.Lower(core.Trim(unit)) switch unit { case "seconds": return "second" diff --git a/time_test.go b/time_test.go index e9ccc4a..e8b7db5 100644 --- a/time_test.go +++ b/time_test.go @@ -173,6 +173,15 @@ func TestFormatAgo_Good_MorePluralUnitAliases(t *testing.T) { } } +func TestFormatAgo_Good_NormalisesUnitInput(t *testing.T) { + svc, err := New() + require.NoError(t, err) + SetDefault(svc) + + got := FormatAgo(2, " Hours ") + assert.Equal(t, "2 hours ago", got) +} + func TestFormatAgo_Bad_UnknownUnit(t *testing.T) { svc, err := New() require.NoError(t, err) -- 2.45.3