mirror of
https://github.com/grafana/grafana.git
synced 2025-02-16 18:34:52 -06:00
Interval: Use gtime for parsing of time string to duration (#40624)
This commit is contained in:
parent
fbc6febb0e
commit
6ec2c54c5b
@ -7,6 +7,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend/gtime"
|
||||
"github.com/grafana/grafana/pkg/tsdb/interval"
|
||||
)
|
||||
|
||||
@ -120,7 +121,7 @@ func ParseIntervalStringToTimeDuration(interval string) (time.Duration, error) {
|
||||
if isPureNum {
|
||||
formattedInterval += "s"
|
||||
}
|
||||
parsedInterval, err := time.ParseDuration(formattedInterval)
|
||||
parsedInterval, err := gtime.ParseDuration(formattedInterval)
|
||||
if err != nil {
|
||||
return time.Duration(0), err
|
||||
}
|
||||
|
@ -112,6 +112,7 @@ func TestGetIntervalFrom(t *testing.T) {
|
||||
{"45s", nil, "45s", 0, time.Second * 15, time.Second * 45},
|
||||
{"45", nil, "45", 0, time.Second * 15, time.Second * 45},
|
||||
{"2m", nil, "2m", 0, time.Second * 15, time.Minute * 2},
|
||||
{"1d", nil, "1d", 0, time.Second * 15, time.Hour * 24},
|
||||
{"intervalMs", nil, "", 45000, time.Second * 15, time.Second * 45},
|
||||
{"intervalMs sub-seconds", nil, "", 45200, time.Second * 15, time.Millisecond * 45200},
|
||||
{"defaultInterval when interval empty", nil, "", 0, time.Second * 15, time.Second * 15},
|
||||
|
Loading…
Reference in New Issue
Block a user