mirror of
https://github.com/kubenetworks/kubevpn.git
synced 2025-10-12 18:51:02 +08:00
26 lines
511 B
Go
26 lines
511 B
Go
package patcher
|
|
|
|
import (
|
|
"time"
|
|
|
|
"github.com/expr-lang/expr/ast"
|
|
)
|
|
|
|
// WithTimezone passes Location to date() and now() functions.
|
|
type WithTimezone struct {
|
|
Location *time.Location
|
|
}
|
|
|
|
func (t WithTimezone) Visit(node *ast.Node) {
|
|
if btin, ok := (*node).(*ast.BuiltinNode); ok {
|
|
switch btin.Name {
|
|
case "date", "now":
|
|
loc := &ast.ConstantNode{Value: t.Location}
|
|
ast.Patch(node, &ast.BuiltinNode{
|
|
Name: btin.Name,
|
|
Arguments: append([]ast.Node{loc}, btin.Arguments...),
|
|
})
|
|
}
|
|
}
|
|
}
|