From 840a9c49c35224d3e0db574b7324aecb29d54d02 Mon Sep 17 00:00:00 2001 From: Aditya Pratap Singh Shekhawat Date: Sat, 7 Feb 2026 16:09:39 +0530 Subject: [PATCH] fix: pluralize time units in created time output Signed-off-by: Aditya Pratap Singh Shekhawat --- pkg/utils/helper.go | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/pkg/utils/helper.go b/pkg/utils/helper.go index 6c6f9e3e4..eefba2815 100644 --- a/pkg/utils/helper.go +++ b/pkg/utils/helper.go @@ -25,6 +25,13 @@ import ( "unicode" ) +func pluralise(value int, unit string) string { + if value == 1 { + return fmt.Sprintf("%d %s ago", value, unit) + } + return fmt.Sprintf("%d %ss ago", value, unit) +} + func FormatCreatedTime(timestamp string) (string, error) { t, err := time.Parse(time.RFC3339Nano, timestamp) if err != nil { @@ -38,11 +45,11 @@ func FormatCreatedTime(timestamp string) (string, error) { days := int(duration.Hours() / 24) if minutes < 60 { - return fmt.Sprintf("%d minute ago", minutes), nil + return pluralise(minutes, "minute"), nil } else if hours < 24 { - return fmt.Sprintf("%d hour ago", hours), nil + return pluralise(hours, "hour"), nil } else { - return fmt.Sprintf("%d day ago", days), nil + return pluralise(days, "day"), nil } }