Skip to content

Commit

Permalink
fix: pluralize sub-second fractions on human time
Browse files Browse the repository at this point in the history
  • Loading branch information
0x2b3bfa0 authored Sep 21, 2023
1 parent 1e98823 commit 00a78b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/skaffold/util/time/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func Humanize(start time.Duration) string {
if out.Minute() > 1 {
longTime = strings.ReplaceAll(longTime, "minute", "minutes")
}
if out.Second() > 1 {
if out.Second() != 1 {
longTime = strings.ReplaceAll(longTime, "second", "seconds")
}
return longTime
Expand Down
9 changes: 9 additions & 0 deletions pkg/skaffold/util/time/time_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ func TestHumanize(t *testing.T) {
if err != nil {
t.Errorf("%s", err)
}
duration3, err := time.ParseDuration("1h3m0.5s")
if err != nil {
t.Errorf("%s", err)
}
tests := []struct {
description string
value time.Duration
Expand All @@ -78,6 +82,11 @@ func TestHumanize(t *testing.T) {
value: duration2,
expected: "5.234 seconds",
},
{
description: "Case for 1h3m0.5s (plural for fraction of second)",
value: duration3,
expected: "1 hour 3 minutes 0.5 seconds",
},
}
for _, test := range tests {
testutil.Run(t, test.description, func(t *testutil.T) {
Expand Down

0 comments on commit 00a78b3

Please sign in to comment.