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:
Michael Schimmel
2026-02-22 08:44:49 +01:00
parent f35606616b
commit 589c13896f
2 changed files with 31 additions and 0 deletions
+10
View File
@@ -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)
});
}