tsdb: sql data sources should handle time ranges before epoch start correctly

This commit is contained in:
Marcus Efraimsson
2018-04-12 18:53:12 +02:00
parent a3874ce2c7
commit f5586b1270
7 changed files with 546 additions and 228 deletions
+16
View File
@@ -15,6 +15,14 @@ func NewTimeRange(from, to string) *TimeRange {
}
}
func NewFakeTimeRange(from, to string, now time.Time) *TimeRange {
return &TimeRange{
From: from,
To: to,
now: now,
}
}
type TimeRange struct {
From string
To string
@@ -25,10 +33,18 @@ func (tr *TimeRange) GetFromAsMsEpoch() int64 {
return tr.MustGetFrom().UnixNano() / int64(time.Millisecond)
}
func (tr *TimeRange) GetFromAsSecondsEpoch() int64 {
return tr.GetFromAsMsEpoch() / 1000
}
func (tr *TimeRange) GetToAsMsEpoch() int64 {
return tr.MustGetTo().UnixNano() / int64(time.Millisecond)
}
func (tr *TimeRange) GetToAsSecondsEpoch() int64 {
return tr.GetToAsMsEpoch() / 1000
}
func (tr *TimeRange) MustGetFrom() time.Time {
if res, err := tr.ParseFrom(); err != nil {
return time.Unix(0, 0)