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 and maoueh committed Nov 29, 2022
1 parent f52c4bd commit 8c34cc8
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 8c34cc8

Please sign in to comment.