-
-
Notifications
You must be signed in to change notification settings - Fork 412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add timezone convert #510
Comments
Go already have In() function https://pkg.go.dev/time#Time.In Expr only need a way to create a Location from a string. Right now I found this way 🫣
|
What about adding timezone()?
|
Hmm, since the date function also accepts the timezone as a string (date("2023-08-14 00:00:00", "2006-01-02 15:04:05", "Europe/Zurich")) it would be cleaner to don't have a separate timezone() function to convert.
Here a couple of ideas:
|
I do not really want to wrap time.Time package into my own. ¯\_(ツ)_/¯ |
Do as you like :-) |
It's a little convoluted when using
|
What about adding TZ param to now()?
|
There's an implementation in #635. |
Another idea: lets overload now() in 'UTC' And also let's add a expr.Timezone() option to configure default timezone for date() and now() functions. expr.Compile(code, expr.Timezone("Europe/Zurich")) |
I've implemented a default timezone option: 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 And a new builtin now().In(timezone("Asia/Kamchatka")) |
Any plans to add the option to convert to a different timezone. I think currently you can only specify a timezone for the input as part of the date() function.
Could be an extra function or an optional parameter of the date function.
date("2023-08-14T00:00:00Z").toTimezone('America/Los_Angeles')
I think it would make sense since its also part of the time package and already used to specify the input date.
The text was updated successfully, but these errors were encountered: