Skip to content

Commit

Permalink
common: improve pretty duration regex (ethereum#25073)
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden authored and gzliudan committed Dec 28, 2024
1 parent ebc0366 commit febb456
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions common/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package common

import (
"fmt"
"regexp"
"strings"
"time"
Expand All @@ -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)
}
Expand Down

0 comments on commit febb456

Please sign in to comment.