Skip to content

Commit

Permalink
common: improve pretty duration regex (ethereum#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 Jun 14, 2022
1 parent 6ad620d commit 8cfd121
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 8cfd121

Please sign in to comment.