Formatting

This commit is contained in:
Michael Schimmel
2026-02-22 02:35:06 +01:00
parent 2123f1d279
commit 329b885c4b
25 changed files with 8053 additions and 6400 deletions
+29 -25
View File
@@ -1,25 +1,29 @@
use crate::ast::types::{Value, StaticType, Signature};
use crate::ast::environment::Environment;
use chrono::{NaiveDate, NaiveDateTime};
pub fn register(env: &Environment) {
let date_ty = StaticType::Function(Box::new(Signature {
params: StaticType::Tuple(vec![StaticType::Text]),
ret: StaticType::DateTime
}));
env.register_native("date", date_ty, true, |args| {
if let Value::Text(s) = &args[0] {
// Try parse YYYY-MM-DD
if let Ok(dt) = NaiveDate::parse_from_str(s, "%Y-%m-%d") {
let ts = dt.and_hms_opt(0, 0, 0).unwrap().and_utc().timestamp_millis();
return Value::DateTime(ts);
}
// Try parse YYYY-MM-DD HH:MM:SS
if let Ok(dt) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S") {
return Value::DateTime(dt.and_utc().timestamp_millis());
}
}
Value::Void
});
}
use crate::ast::environment::Environment;
use crate::ast::types::{Signature, StaticType, Value};
use chrono::{NaiveDate, NaiveDateTime};
pub fn register(env: &Environment) {
let date_ty = StaticType::Function(Box::new(Signature {
params: StaticType::Tuple(vec![StaticType::Text]),
ret: StaticType::DateTime,
}));
env.register_native("date", date_ty, true, |args| {
if let Value::Text(s) = &args[0] {
// Try parse YYYY-MM-DD
if let Ok(dt) = NaiveDate::parse_from_str(s, "%Y-%m-%d") {
let ts = dt
.and_hms_opt(0, 0, 0)
.unwrap()
.and_utc()
.timestamp_millis();
return Value::DateTime(ts);
}
// Try parse YYYY-MM-DD HH:MM:SS
if let Ok(dt) = NaiveDateTime::parse_from_str(s, "%Y-%m-%d %H:%M:%S") {
return Value::DateTime(dt.and_utc().timestamp_millis());
}
}
Value::Void
});
}