Skip to content
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 Optional Timezone to now() #635

Closed
wants to merge 2 commits into from

Conversation

cwarden
Copy link
Contributor

@cwarden cwarden commented Apr 26, 2024

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

Add support for an optional timezone argument to now().  Formatting the
returned time will use the specified timezone.
@cwarden cwarden mentioned this pull request Apr 26, 2024
go.mod Outdated
@@ -2,7 +2,10 @@ module github.com/expr-lang/expr

go 1.18

require github.com/stretchr/testify v1.8.4
require (
github.com/agiledragon/gomonkey/v2 v2.11.0
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's not add additional dependencies.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's just a test dependency to address the race in the tests. Any other preferred method for avoiding the race condition, or just leave it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a security concern. I'm also will be happy to avoid testify if possible. I understand what this is test dep, but apparently vet tools not: #618

Remove dependency on gomonkey in tests.  Allow race condition in which
clock may tick to the next minute between time.Now() calls.
@antonmedv
Copy link
Member

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

@antonmedv antonmedv closed this May 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants