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

Allow for predefined "constants" in time formatting built-ins #5945

Closed
anderseknert opened this issue May 24, 2023 · 6 comments · Fixed by #6005
Closed

Allow for predefined "constants" in time formatting built-ins #5945

anderseknert opened this issue May 24, 2023 · 6 comments · Fixed by #6005

Comments

@anderseknert
Copy link
Member

anderseknert commented May 24, 2023

The golang time formatting "reference date" is... questionable, and sadly something we've inherited in OPA. To make things at least somewhat bearable, it would be great if we could support the predefined constants for common datetime formats as supported by Go, like RFC1123 (and others). We don't really have constants in Rego exposed like we have built-in functions, but I guess it would be possible to provide something like that.

If not:

time.format([time.now_ns(), "UTC", time.formatting.RFC1123])

Perhaps we could just allow the string value, like:

time.format([time.now_ns(), "UTC", "RFC1123"])

Applies to time.format and time.parse_ns.

Issue created from disucssion with @JinXiu2023

@tjons
Copy link
Contributor

tjons commented Jun 8, 2023

@ashutosh-narkar I'd like to take a crack at this if that's okay?

@anderseknert
Copy link
Member Author

Of course @tjons 👍 I think we should go with just string literals as we aren't using constants anywhere else in the "stdlib".

@yogisinha
Copy link
Contributor

yogisinha commented Jun 11, 2023

Hi @anderseknert which package/files should I look into for this. I just want to explore. I won't do anything as @tjons is already on it.

@yogisinha
Copy link
Contributor

yogisinha commented Jun 11, 2023

@anderseknert I tried to look in this code. I guess builtinFormat function in time.go file needs to be changed. right ?

@anderseknert
Copy link
Member Author

Yep, looks about right to me 👍

@tjons
Copy link
Contributor

tjons commented Jun 12, 2023

Opened #6005 to add this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants