Extend pkg/expr functions

This commit is contained in:
Tomaž Jerman
2020-12-14 12:37:44 +01:00
parent 68cd9c218e
commit ed6c4291d8
2 changed files with 7 additions and 3 deletions
+4 -1
View File
@@ -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),
}
}
+3 -2
View File
@@ -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
}