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
+9
View File
@@ -33,6 +33,9 @@ mod utils;
#[cfg(feature = "uuid")]
mod uuid;
#[cfg(feature = "opa-testutil")]
mod test;
use crate::ast::{Expr, Ref};
use crate::lexer::Span;
use crate::value::Value;
@@ -76,6 +79,7 @@ lazy_static! {
encoding::register(&mut m);
//token_signing::register(&mut m);
//token_verification::register(&mut m);
#[cfg(feature = "time")]
time::register(&mut m);
#[cfg(feature = "crypto")]
@@ -92,6 +96,10 @@ lazy_static! {
debugging::register(&mut m);
tracing::register(&mut m);
units::register(&mut m);
#[cfg(feature = "opa-testutil")]
test::register(&mut m);
m
};
}
@@ -100,6 +108,7 @@ pub fn must_cache(path: &str) -> Option<&'static str> {
match path {
"rand.intn" => Some("rand.intn"),
"uuid.rfc4122" => Some("uuid.rfc4122"),
"time.now_ns" => Some("time.now_ns"),
_ => None,
}
}