expr-lang / expr

Expression language and expression evaluation for Go
https://expr-lang.org
MIT License
5.85k stars 378 forks source link

Add Optional Timezone to now() #635

Closed cwarden closed 2 months ago

cwarden commented 2 months ago

Add support for an optional timezone argument to now(). Formatting the returned time will use the specified timezone.

antonmedv commented 2 months ago

I've implemented default timezone and timezone() builtins.

program, err := expr.Compile(`now().Location().String()`, expr.Timezone("Asia/Kamchatka"))
if err != nil {
    fmt.Printf("%v", err)
    return
}

output, err := expr.Run(program, nil)
if err != nil {
    fmt.Printf("%v", err)
    return
}

fmt.Printf("%v", output)
// Output: Asia/Kamchatka