mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-06-19 21:31:37 +00:00
common: improve pretty duration regex (#25073)
This commit is contained in:
parent
ebc036682e
commit
febb456ddd
1 changed files with 2 additions and 3 deletions
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue