sql datasource: extract common logic for converting time column to epoch time in ms

This commit is contained in:
Marcus Efraimsson
2018-03-20 19:40:10 +01:00
parent e5e9d3c2f3
commit 3cb0bc3da1
3 changed files with 84 additions and 0 deletions

View File

@@ -88,3 +88,13 @@ func (tr *TimeRange) ParseTo() (time.Time, error) {
return time.Time{}, fmt.Errorf("cannot parse to value %s", tr.To)
}
// EpochPrecisionToMs converts epoch precision to millisecond, if needed.
// Only seconds to milliseconds supported right now
func EpochPrecisionToMs(value float64) float64 {
if int64(value)/1e10 == 0 {
return float64(value * 1e3)
}
return float64(value)
}