-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Built-ins: time diff function #3348
Comments
One way of doing this currently is something like https://play.openpolicyagent.org/p/ZDLf9k1fuC. The time-builtins use Go's time package. Feel free to add a new one ! |
I should have been more specific. I was thinking of a difference on the format I am not sure if the required logic is possible to implement with Rego, so I will start on adding the new builtin. I was thinking of something like this:
Any comments on this format @ashutosh-narkar? |
This seems reasonable to me. Or even [hour, minute, second] which is what the |
This built-in function makes it possible to get the absolute difference between to unix timestamps (nanoseconds since epoch) on the format [year, month, day, hour, minute, second]. Fixes: open-policy-agent#3348 Signed-off-by: Andre Håland <andre.haland@gmail.com>
This built-in function makes it possible to get the absolute difference between to unix timestamps (nanoseconds since epoch) on the format [year, month, day, hour, minute, second]. Fixes: #3348 Signed-off-by: Andre Håland <andre.haland@gmail.com>
There are some use cases for calculating the difference between two
Time
values (e.g. calculate time since last login, or calculate the age based on birthdate). Is this something that would be accepted as an addition to thetime
built-ins?output := time.diff(a, b)
Example implementation can be seen from this SO post:
https://stackoverflow.com/a/36531443
The text was updated successfully, but these errors were encountered: