From 0f9c8d91efad4bae6db254c04c6ae6a5214abd02 Mon Sep 17 00:00:00 2001 From: Prashant Shahi Date: Fri, 31 May 2024 21:22:03 +0530 Subject: [PATCH] chore(query-service): update `GoValuateFuncs` definitions (#5106) * fix: parse both unix int and RFC3339 string in toUnixTimestamp * chore: return GoValuateFuncs as float64 * chore: remove toUnixTimestamp function --------- Signed-off-by: Prashant Shahi --- pkg/query-service/postprocess/formula.go | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/pkg/query-service/postprocess/formula.go b/pkg/query-service/postprocess/formula.go index b88677b0be..f88ceb77a1 100644 --- a/pkg/query-service/postprocess/formula.go +++ b/pkg/query-service/postprocess/formula.go @@ -266,20 +266,9 @@ func EvalFuncs() map[string]govaluate.ExpressionFunction { GoValuateFuncs["radians"] = func(args ...interface{}) (interface{}, error) { return args[0].(float64) * math.Pi / 180, nil } - + // Returns the current Unix timestamp in seconds. GoValuateFuncs["now"] = func(args ...interface{}) (interface{}, error) { - return time.Now().Unix(), nil - } - - GoValuateFuncs["toUnixTimestamp"] = func(args ...interface{}) (interface{}, error) { - if len(args) != 1 { - return nil, fmt.Errorf("toUnixTimestamp requires exactly one argument") - } - t, err := time.Parse(time.RFC3339, args[0].(string)) - if err != nil { - return nil, err - } - return t.Unix(), nil + return float64(time.Now().Unix()), nil } return GoValuateFuncs