Skip to content

Commit e77f5d5

Browse files
authored
Update format.go
1 parent 7805e20 commit e77f5d5

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

common/format.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@
1717
package common
1818

1919
import (
20-
"fmt"
2120
"regexp"
21+
"strconv"
2222
"strings"
2323
"time"
2424
)
@@ -66,17 +66,21 @@ func (t PrettyAge) String() string {
6666
return "0"
6767
}
6868
// Accumulate a precision of 3 components before returning
69-
result, prec := "", 0
69+
var (
70+
builder strings.Builder
71+
prec int
72+
)
7073

7174
for _, unit := range ageUnits {
7275
if diff >= unit.Size {
73-
result = fmt.Sprintf("%s%d%s", result, diff/unit.Size, unit.Symbol)
76+
builder.WriteString(strconv.FormatInt(int64(diff/unit.Size), 10))
77+
builder.WriteString(unit.Symbol)
7478
diff %= unit.Size
7579

7680
if prec += 1; prec >= 3 {
7781
break
7882
}
7983
}
8084
}
81-
return result
85+
return builder.String()
8286
}

0 commit comments

Comments
 (0)