Unverified Commit 8cfd1214 authored by Marius van der Wijden's avatar Marius van der Wijden Committed by GitHub

common: improve pretty duration regex (#25073)

* common: improve pretty duration regex

* common: improve pretty duration regex
parent 6ad620d6
...@@ -27,12 +27,12 @@ import ( ...@@ -27,12 +27,12 @@ import (
// the unnecessary precision off from the formatted textual representation. // the unnecessary precision off from the formatted textual representation.
type PrettyDuration time.Duration 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 // String implements the Stringer interface, allowing pretty printing of duration
// values rounded to three decimals. // values rounded to three decimals.
func (d PrettyDuration) String() string { 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 { if match := prettyDurationRe.FindString(label); len(match) > 4 {
label = strings.Replace(label, match, match[:4], 1) label = strings.Replace(label, match, match[:4], 1)
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment