github.com/expr-lang/expr@v1.16.9/patcher/with_timezone.go (about) 1 package patcher 2 3 import ( 4 "time" 5 6 "github.com/expr-lang/expr/ast" 7 ) 8 9 // WithTimezone passes Location to date() and now() functions. 10 type WithTimezone struct { 11 Location *time.Location 12 } 13 14 func (t WithTimezone) Visit(node *ast.Node) { 15 if btin, ok := (*node).(*ast.BuiltinNode); ok { 16 switch btin.Name { 17 case "date", "now": 18 loc := &ast.ConstantNode{Value: t.Location} 19 ast.Patch(node, &ast.BuiltinNode{ 20 Name: btin.Name, 21 Arguments: append([]ast.Node{loc}, btin.Arguments...), 22 }) 23 } 24 } 25 }