mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
add GetFromAsTimeUTC and GetToAsTimeUTC and use them in timeFilter macro
This commit is contained in:
@@ -83,7 +83,7 @@ func (m *PostgresMacroEngine) evaluateMacro(name string, args []string) (string,
|
|||||||
return "", fmt.Errorf("missing time column argument for macro %v", name)
|
return "", fmt.Errorf("missing time column argument for macro %v", name)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("%s BETWEEN '%s' AND '%s'", args[0], m.TimeRange.MustGetFrom().UTC().Format(time.RFC3339), m.TimeRange.MustGetTo().UTC().Format(time.RFC3339)), nil
|
return fmt.Sprintf("%s BETWEEN '%s' AND '%s'", args[0], m.TimeRange.GetFromAsTimeUTC().Format(time.RFC3339), m.TimeRange.GetToAsTimeUTC().Format(time.RFC3339)), nil
|
||||||
case "__timeFrom":
|
case "__timeFrom":
|
||||||
return fmt.Sprintf("to_timestamp(%d)", m.TimeRange.GetFromAsSecondsEpoch()), nil
|
return fmt.Sprintf("to_timestamp(%d)", m.TimeRange.GetFromAsSecondsEpoch()), nil
|
||||||
case "__timeTo":
|
case "__timeTo":
|
||||||
|
|||||||
@@ -37,6 +37,10 @@ func (tr *TimeRange) GetFromAsSecondsEpoch() int64 {
|
|||||||
return tr.GetFromAsMsEpoch() / 1000
|
return tr.GetFromAsMsEpoch() / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tr *TimeRange) GetFromAsTimeUTC() time.Time {
|
||||||
|
return tr.MustGetFrom().UTC()
|
||||||
|
}
|
||||||
|
|
||||||
func (tr *TimeRange) GetToAsMsEpoch() int64 {
|
func (tr *TimeRange) GetToAsMsEpoch() int64 {
|
||||||
return tr.MustGetTo().UnixNano() / int64(time.Millisecond)
|
return tr.MustGetTo().UnixNano() / int64(time.Millisecond)
|
||||||
}
|
}
|
||||||
@@ -45,6 +49,10 @@ func (tr *TimeRange) GetToAsSecondsEpoch() int64 {
|
|||||||
return tr.GetToAsMsEpoch() / 1000
|
return tr.GetToAsMsEpoch() / 1000
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (tr *TimeRange) GetToAsTimeUTC() time.Time {
|
||||||
|
return tr.MustGetTo().UTC()
|
||||||
|
}
|
||||||
|
|
||||||
func (tr *TimeRange) MustGetFrom() time.Time {
|
func (tr *TimeRange) MustGetFrom() time.Time {
|
||||||
if res, err := tr.ParseFrom(); err != nil {
|
if res, err := tr.ParseFrom(); err != nil {
|
||||||
return time.Unix(0, 0)
|
return time.Unix(0, 0)
|
||||||
|
|||||||
Reference in New Issue
Block a user