Skip to content

Commit

Permalink
common: improve pretty duration regex (#25073)
Browse files Browse the repository at this point in the history
* common: improve pretty duration regex

* common: improve pretty duration regex
  • Loading branch information
MariusVanDerWijden authored and brilliant-lx committed Oct 28, 2022
1 parent 5d21a7c commit bd79e2d
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,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)
}
Expand Down

0 comments on commit bd79e2d

Please sign in to comment.