From ed6c4291d8873248f8c125cc2c67b05ea9e99303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Toma=C5=BE=20Jerman?= Date: Mon, 14 Dec 2020 12:37:44 +0100 Subject: [PATCH] Extend pkg/expr functions --- pkg/expr/func_str.go | 5 ++++- pkg/expr/func_time.go | 5 +++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pkg/expr/func_str.go b/pkg/expr/func_str.go index f0efa84a4..c89d895ba 100644 --- a/pkg/expr/func_str.go +++ b/pkg/expr/func_str.go @@ -1,8 +1,10 @@ package expr import ( - "github.com/PaesslerAG/gval" + "fmt" "strings" + + "github.com/PaesslerAG/gval" ) func StringFunctions() []gval.Language { @@ -15,6 +17,7 @@ func StringFunctions() []gval.Language { gval.Function("toUpper", strings.ToUpper), gval.Function("shortest", shortest), gval.Function("longest", longest), + gval.Function("format", fmt.Sprintf), } } diff --git a/pkg/expr/func_time.go b/pkg/expr/func_time.go index af610e546..f88d28425 100644 --- a/pkg/expr/func_time.go +++ b/pkg/expr/func_time.go @@ -1,9 +1,10 @@ package expr import ( + "time" + "github.com/PaesslerAG/gval" "github.com/lestrrat-go/strftime" - "time" ) func TimeFunctions() []gval.Language { @@ -64,6 +65,6 @@ func modTime(t time.Time, mod interface{}) (time.Time, error) { // More details here: // https://github.com/lestrrat-go/strftime#supported-conversion-specifications func strfTime(t time.Time, f string) string { - o, _ := strftime.Format(f, t) + o, _ := strftime.Format(f, t, strftime.WithMilliseconds('b')) return o }