use crate::{QueryError, Result, Scalar, Value}; use chrono::{DateTime, TimeZone, Utc}; impl Scalar for DateTime { fn type_name() -> &'static str { "DateTime" } fn parse(value: Value) -> Result { match value { Value::String(s) => Ok(Utc.datetime_from_str(&s, "%+")?), _ => { return Err(QueryError::ExpectedType { expect: Self::type_name().to_string(), actual: value, } .into()) } } } fn parse_from_json(value: serde_json::Value) -> Result { match value { serde_json::Value::String(s) => Ok(Utc.datetime_from_str(&s, "%+")?), _ => { return Err(QueryError::ExpectedJsonType { expect: Self::type_name().to_string(), actual: value, } .into()) } } } fn into_json(self) -> Result { Ok(self.to_rfc3339().into()) } }