mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
interval: make the FormatDuration function public
A useful function that was ported from kbn.ts and can be used to convert milliseconds into a kbn unit
This commit is contained in:
parent
d6904ba9b4
commit
a54484638d
@ -59,11 +59,11 @@ func (ic *intervalCalculator) Calculate(timerange *TimeRange, minInterval time.D
|
||||
interval := time.Duration((to - from) / defaultRes)
|
||||
|
||||
if interval < minInterval {
|
||||
return Interval{Text: formatDuration(minInterval), Value: minInterval}
|
||||
return Interval{Text: FormatDuration(minInterval), Value: minInterval}
|
||||
}
|
||||
|
||||
rounded := roundInterval(interval)
|
||||
return Interval{Text: formatDuration(rounded), Value: rounded}
|
||||
return Interval{Text: FormatDuration(rounded), Value: rounded}
|
||||
}
|
||||
|
||||
func GetIntervalFrom(dsInfo *models.DataSource, queryModel *simplejson.Json, defaultInterval time.Duration) (time.Duration, error) {
|
||||
@ -89,7 +89,8 @@ func GetIntervalFrom(dsInfo *models.DataSource, queryModel *simplejson.Json, def
|
||||
return parsedInterval, nil
|
||||
}
|
||||
|
||||
func formatDuration(inter time.Duration) string {
|
||||
// FormatDuration converts a duration into the kbn format e.g. 1m 2h or 3d
|
||||
func FormatDuration(inter time.Duration) string {
|
||||
if inter >= year {
|
||||
return fmt.Sprintf("%dy", inter/year)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user