-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
allow time formatting constants in rego time.format and time.parse_ns #6005
allow time formatting constants in rego time.format and time.parse_ns #6005
Conversation
Signed-off-by: Tyler Schade <tyler.schade@solo.io>
✅ Deploy Preview for openpolicyagent ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Signed-off-by: Tyler Schade <tyler.schade@solo.io>
…nto add-constants-to-time-format
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Thanks. Skimming the docs on the date/time built-ins just now and it strikes me that we probably want this capability for time.parse_ns
too, or what do you think?
Doesn't have to be included in this PR, but I suppose it's simple enough to do.
@ashutosh-narkar yep, I can do that right now. @anderseknert - I agree, was thinking of that when I did the PR. Since it's not part of the original issue, do you want me to create a new issue for it or just handle it in this one? Happy to contribute that as well. |
Signed-off-by: Tyler Schade <tyler.schade@solo.io>
It's small enough that adding it here seems fine. I'll update the issue to reflect that 👍 |
Signed-off-by: Tyler Schade <tyler.schade@solo.io>
Ah, just noticed there's a section on timestamp parsing here: https://www.openpolicyagent.org/docs/latest/policy-reference/#timestamp-parsing Perhaps we could add something about this there? Either a list of the constants available, or a link to somewhere else where they are explained. Sorry for the scope creep @tjons 😅 |
Signed-off-by: Tyler Schade <tyler.schade@solo.io>
All good @anderseknert. Done - let me know what you think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's putting a bit more burden on non-golang-based implementations (wasm, IR-based things), but that's OK, I think. Thanks for contributing 👏
@srenatus can you expound on that to help me understand? From skimming the WASM docs it looks like the |
Any builtins that don't have a native wasm implementation (read: another implementation written in in C) will be unavailable to Wasm users, unless
Now, for (2.), and SDKs that are not based on Golang, the builtin implementation will have to figure out what golang does, and replicate it. The only way to avoid that would be to write a native implementation; but then that work would go into writing that. |
@srenatus makes sense, thank you. hard to avoid here since we are replicating the golang feature but good to note. |
@tjons exactly. OTOH, it's not as bad as golang |
…open-policy-agent#6005) Allow time formatting constants in `time.format` and `time.parse_ns` Signed-off-by: Tyler Schade <tyler.schade@solo.io> Signed-off-by: Fred Feng <superffeng@gmail.com>
Why the changes in this PR are needed?
Resolves #5945
What are the changes in this PR?
Add support for Go standard library format constants when calling
time.format
. If the third parameter is passed totime.format
and is a valid constant name for a timestamp format in the Go standard library, it will be used to format the timestamp. Otherwise, the string will be treated as a format string and may error.