From febb456ddd3e96aad420a8764d3632ef42c28af6 Mon Sep 17 00:00:00 2001 From: Marius van der Wijden Date: Tue, 14 Jun 2022 14:08:43 +0200 Subject: [PATCH] common: improve pretty duration regex (#25073) --- common/format.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/common/format.go b/common/format.go index fccc299620dc..197e8697d9af 100644 --- a/common/format.go +++ b/common/format.go @@ -17,7 +17,6 @@ package common import ( - "fmt" "regexp" "strings" "time" @@ -27,12 +26,12 @@ import ( // the unnecessary precision off from the formatted textual representation. type PrettyDuration time.Duration -var prettyDurationRe = regexp.MustCompile(`\.[0-9]+`) +var prettyDurationRe = regexp.MustCompile(`\.[0-9]{4,}`) // String implements the Stringer interface, allowing pretty printing of duration // values rounded to three decimals. func (d PrettyDuration) String() string { - label := fmt.Sprintf("%v", time.Duration(d)) + label := time.Duration(d).String() if match := prettyDurationRe.FindString(label); len(match) > 4 { label = strings.Replace(label, match, match[:4], 1) }