Interval: Use gtime for parsing of time string to duration (#40624)

This commit is contained in:
Ivana Huckova 2021-10-19 14:56:57 +02:00 committed by GitHub
parent fbc6febb0e
commit 6ec2c54c5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 1 deletions

View File

@ -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
}

View File

@ -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},