Implement most of the builtin time module (#82)

* Implement builtin `time.add_date` method

* Implement builtin `time.clock` method

* Implement builtin `time.date` method

* Implement builtin `time.diff` method

* Implement builtin `time.format` method

* Migrate `time.now_ns` to `chrono`

* Implement builtin `time.parse_ns` method

* Implement builtin `time.parse_rfc3339_ns` method

* Implement builtin `time.weekday` method

* Add conditional `test` module for OPA tests

* Cache result of `time.now_ns`

* Fail in strict mode if timestamp is outside of range

* Add `ensure_i32` util

* Move `diff_between_datetimes` into its own file and include appropriate license
This commit is contained in:
Burak
2024-01-01 01:07:39 +00:00
committed by GitHub
parent 2292774446
commit d2eb3ecd1f
14 changed files with 1002 additions and 12 deletions
+22 -1
View File
@@ -20,8 +20,27 @@ regex = ["dep:regex"]
semver = ["dep:semver"]
uuid = ["dep:uuid"]
urlquery = ["dep:url"]
time = ["dep:chrono", "dep:chrono-tz"]
yaml = ["serde_yaml"]
full-opa = ["base64", "base64url", "crypto", "deprecated", "glob", "graph", "hex", "jsonschema", "regex", "semver", "uuid", "urlquery", "yaml"]
full-opa = [
"base64",
"base64url",
"crypto",
"deprecated",
"glob",
"graph",
"hex",
"jsonschema",
"regex",
"semver",
"uuid",
"urlquery",
"time",
"yaml"
]
# This feature enables some testing utils for OPA tests.
opa-testutil = []
[dependencies]
anyhow = {version = "1.0.66", features = ["backtrace"] }
@@ -51,6 +70,8 @@ wax = { version = "0.6.0", features = [], default-features = false, optional = t
url = { version = "2.5.0", optional = true }
uuid = { version = "1.6.1", features = ["v4", "fast-rng"], optional = true }
jsonschema = { version = "0.17.1", default-features = false, optional = true }
chrono = { version = "0.4.31", optional = true }
chrono-tz = { version = "0.8.5", optional = true }
[dev-dependencies]