Add now() built-in function
This commit introduces the `now()` built-in function, which returns the current timestamp in milliseconds. It also includes an integration test to ensure that `now()` is not constant-folded during AST dumping, verifying its non-deterministic nature.
This commit is contained in:
@@ -27,4 +27,14 @@ pub fn register(env: &Environment) {
|
||||
}
|
||||
Value::Void
|
||||
});
|
||||
|
||||
let now_ty = StaticType::Function(Box::new(Signature {
|
||||
params: StaticType::Tuple(vec![]),
|
||||
ret: StaticType::DateTime,
|
||||
}));
|
||||
|
||||
env.register_native("now", now_ty, Purity::SideEffectFree, |_| {
|
||||
let ts = chrono::Utc::now().timestamp_millis();
|
||||
Value::DateTime(ts)
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user