forked from open-policy-agent/opa
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
time.format: new builtin to get string timestamp for ns (open-policy-…
…agent#5432) Adds a builtin time.format to format time given in ns to a string timestamp for the given timezone or UTC as default. The builtin takes in 3 types of arguments: 1. An integer value representing the time in nanoseconds since epoch 2. An array with the first value as integer representing the time in ns and second argument as string value representing the timezone. In the first case, when only an integer value is provided, UTC timezone is considered The function returns a string type value of the timestamp in the RFC3339Nano format. E.g. 2022-11-23T18:20:14Z 3. An array with the first value the integer ns, the second a string timezone, and third a string for the format, to use one different from RFC3339Nano. Signed-off-by: burnerlee <[email protected]>
- Loading branch information
Showing
5 changed files
with
154 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
cases: | ||
- data: | ||
modules: | ||
- | | ||
package test | ||
time_ns := 1670006453141828752 | ||
a := time.format(time_ns) | ||
b := time.format([time_ns, "Asia/Kolkata"]) | ||
c := time.format([time_ns,"Asia/Kolkata","Mon Jan 02 15:04:05 -0700 2006"]) | ||
note: time/format | ||
query: > | ||
data.test.a = no_timezone; | ||
data.test.b = with_timezone; | ||
data.test.c = with_layout | ||
want_result: | ||
- no_timezone: "2022-12-02T18:40:53.141828752Z" | ||
with_timezone: "2022-12-03T00:10:53.141828752+05:30" | ||
with_layout: "Sat Dec 03 00:10:53 +0530 2022" | ||
- data: | ||
modules: | ||
- | | ||
package generated | ||
p := time.format(1582977600 * 10e12) | ||
note: time/format too big | ||
query: data.generated.p = x | ||
want_error: timestamp too big | ||
want_error_code: eval_builtin_error | ||
strict_error: true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters