diff --git a/lib/src/fnc/is.rs b/lib/src/fnc/is.rs index 9188fdaf..32cfef22 100644 --- a/lib/src/fnc/is.rs +++ b/lib/src/fnc/is.rs @@ -1,5 +1,6 @@ use crate::err::Error; use crate::sql::value::Value; +use chrono::NaiveDateTime; use once_cell::sync::Lazy; use regex::Regex; use semver::Version; @@ -25,6 +26,11 @@ pub fn ascii((arg,): (String,)) -> Result { Ok(arg.is_ascii().into()) } +#[inline] +pub fn datetime((arg, fmt): (String, String)) -> Result { + Ok(NaiveDateTime::parse_from_str(&arg, &fmt).is_ok().into()) +} + #[inline] pub fn domain((arg,): (String,)) -> Result { Ok(addr::parse_domain_name(arg.as_str()).is_ok().into()) diff --git a/lib/src/fnc/mod.rs b/lib/src/fnc/mod.rs index 4eb62a08..b7cf3481 100644 --- a/lib/src/fnc/mod.rs +++ b/lib/src/fnc/mod.rs @@ -99,6 +99,7 @@ pub fn synchronous(ctx: &Context<'_>, name: &str, args: Vec) -> Result is::alphanum, "is::alpha" => is::alpha, "is::ascii" => is::ascii, + "is::datetime" => is::datetime, "is::domain" => is::domain, "is::email" => is::email, "is::hexadecimal" => is::hexadecimal, diff --git a/lib/src/fnc/script/modules/surrealdb/functions/is.rs b/lib/src/fnc/script/modules/surrealdb/functions/is.rs index 2baf484e..4a2781f8 100644 --- a/lib/src/fnc/script/modules/surrealdb/functions/is.rs +++ b/lib/src/fnc/script/modules/surrealdb/functions/is.rs @@ -21,6 +21,7 @@ impl ModuleDef for Package { module.add("alphanum")?; module.add("alpha")?; module.add("ascii")?; + module.add("datetime")?; module.add("domain")?; module.add("email")?; module.add("hexadecimal")?; @@ -38,6 +39,7 @@ impl ModuleDef for Package { module.set("alphanum", Func::from(|v: Any| run("is::alphanum", v.0)))?; module.set("alpha", Func::from(|v: Any| run("is::alpha", v.0)))?; module.set("ascii", Func::from(|v: Any| run("is::ascii", v.0)))?; + module.set("datetime", Func::from(|v: Any| run("is::datetime", v.0)))?; module.set("domain", Func::from(|v: Any| run("is::domain", v.0)))?; module.set("email", Func::from(|v: Any| run("is::email", v.0)))?; module.set("hexadecimal", Func::from(|v: Any| run("is::hexadecimal", v.0)))?; @@ -52,6 +54,7 @@ impl ModuleDef for Package { default.set("alphanum", Func::from(|v: Any| run("is::alphanum", v.0)))?; default.set("alpha", Func::from(|v: Any| run("is::alpha", v.0)))?; default.set("ascii", Func::from(|v: Any| run("is::ascii", v.0)))?; + default.set("datetime", Func::from(|v: Any| run("is::datetime", v.0)))?; default.set("domain", Func::from(|v: Any| run("is::domain", v.0)))?; default.set("email", Func::from(|v: Any| run("is::email", v.0)))?; default.set("hexadecimal", Func::from(|v: Any| run("is::hexadecimal", v.0)))?; diff --git a/lib/src/sql/function.rs b/lib/src/sql/function.rs index 568c0a00..f5f84326 100644 --- a/lib/src/sql/function.rs +++ b/lib/src/sql/function.rs @@ -310,6 +310,7 @@ fn function_is(i: &str) -> IResult<&str, &str> { tag("is::alphanum"), tag("is::alpha"), tag("is::ascii"), + tag("is::datetime"), tag("is::domain"), tag("is::email"), tag("is::hexadecimal"),