use chrono::{Local, Timelike};
use crate::eval::functions::{check_arity_len, EvalCtx};
use crate::eval::functions::date::serial::{date_to_serial, time_to_serial};
use crate::parser::ast::Expr;
use crate::types::Value;
pub fn now_fn(args: &[Expr], ctx: &mut EvalCtx<'_>) -> Value {
if let Some(e) = check_arity_len(args.len(), 0, 0) {
return e;
}
let serial = match ctx.ctx.now_serial {
Some(now) => now,
None => {
let now = Local::now().naive_local();
date_to_serial(now.date()) + time_to_serial(now.hour(), now.minute(), now.second())
}
};
Value::Number(serial)
}
#[cfg(test)]
mod tests;