Added unix strftime support to gval functions

This commit is contained in:
Peter Grlica
2021-12-08 10:21:50 +01:00
parent 486a5752b2
commit d5001341ad
2 changed files with 13 additions and 1 deletions
+6 -1
View File
@@ -190,10 +190,15 @@ func prepMod(base interface{}, mod interface{}) (*time.Time, int, error) {
// https://github.com/lestrrat-go/strftime#supported-conversion-specifications
func strfTime(base interface{}, f string) (string, error) {
t, _, err := prepMod(base, 0)
if err != nil {
return "", err
}
o, _ := strftime.Format(f, *t, strftime.WithMilliseconds('b'))
o, _ := strftime.Format(f, *t,
strftime.WithMilliseconds('b'),
strftime.WithUnixSeconds('L'))
return o, nil
}
+7
View File
@@ -134,3 +134,10 @@ func Example_subErrorCheck() {
// output:
// error: can not evaluate sub(ghd, hgp): expecting 2nd input to be less than 1st input
}
func Example_unix() {
eval(`strftime(ghd, "%L")`, exampleTimeParams)
// output:
// 728650800
}