mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
intervalv2: use duration-formatting logic from plugin-sdk-go (#81690)
This commit is contained in:
parent
5c9913b65d
commit
ddf124de9d
@ -1,7 +1,6 @@
|
|||||||
package intervalv2
|
package intervalv2
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
@ -13,8 +12,6 @@ import (
|
|||||||
var (
|
var (
|
||||||
DefaultRes int64 = 1500
|
DefaultRes int64 = 1500
|
||||||
defaultMinInterval = time.Millisecond * 1
|
defaultMinInterval = time.Millisecond * 1
|
||||||
year = time.Hour * 24 * 365
|
|
||||||
day = time.Hour * 24
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Interval struct {
|
type Interval struct {
|
||||||
@ -129,31 +126,7 @@ func ParseIntervalStringToTimeDuration(interval string) (time.Duration, error) {
|
|||||||
|
|
||||||
// FormatDuration converts a duration into the kbn format e.g. 1m 2h or 3d
|
// FormatDuration converts a duration into the kbn format e.g. 1m 2h or 3d
|
||||||
func FormatDuration(inter time.Duration) string {
|
func FormatDuration(inter time.Duration) string {
|
||||||
if inter >= year {
|
return gtime.FormatInterval(inter)
|
||||||
return fmt.Sprintf("%dy", inter/year)
|
|
||||||
}
|
|
||||||
|
|
||||||
if inter >= day {
|
|
||||||
return fmt.Sprintf("%dd", inter/day)
|
|
||||||
}
|
|
||||||
|
|
||||||
if inter >= time.Hour {
|
|
||||||
return fmt.Sprintf("%dh", inter/time.Hour)
|
|
||||||
}
|
|
||||||
|
|
||||||
if inter >= time.Minute {
|
|
||||||
return fmt.Sprintf("%dm", inter/time.Minute)
|
|
||||||
}
|
|
||||||
|
|
||||||
if inter >= time.Second {
|
|
||||||
return fmt.Sprintf("%ds", inter/time.Second)
|
|
||||||
}
|
|
||||||
|
|
||||||
if inter >= time.Millisecond {
|
|
||||||
return fmt.Sprintf("%dms", inter/time.Millisecond)
|
|
||||||
}
|
|
||||||
|
|
||||||
return "1ms"
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//nolint:gocyclo
|
//nolint:gocyclo
|
||||||
|
Loading…
Reference in New Issue
Block a user