diff --git a/crates/store/src/timestamp.rs b/crates/store/src/timestamp.rs index 5559594..ee57543 100644 --- a/crates/store/src/timestamp.rs +++ b/crates/store/src/timestamp.rs @@ -4,6 +4,7 @@ use crate::Error; use anyhow::{anyhow, Result}; use chrono::{DateTime, Duration, NaiveDate, NaiveDateTime, NaiveTime, Utc}; use lazy_static::lazy_static; +use serde::Deserialize; lazy_static! { static ref RE_DURATION: regex::Regex = regex::Regex::new(r"^(?[+-])?P((?P\d+)W)?((?P\d+)D)?(T((?P\d+)H)?((?P\d+)M)?((?P\d+)S)?)?$").unwrap(); @@ -13,6 +14,7 @@ const LOCAL_DATE_TIME: &str = "%Y%m%dT%H%M%S"; const UTC_DATE_TIME: &str = "%Y%m%dT%H%M%SZ"; const LOCAL_DATE: &str = "%Y%m%d"; +#[derive(Debug, Clone)] pub enum CalDateTime { // Form 1, example: 19980118T230000 Local(NaiveDateTime), @@ -24,6 +26,16 @@ pub enum CalDateTime { Date(NaiveDate), } +impl<'de> Deserialize<'de> for CalDateTime { + fn deserialize(deserializer: D) -> std::result::Result + where + D: serde::Deserializer<'de>, + { + let input = String::deserialize(deserializer)?; + Self::from_str(&input).map_err(|_| serde::de::Error::custom("Invalid datetime format")) + } +} + impl Add for CalDateTime { type Output = Self;