use serde::{Deserialize, Deserializer}; use time::format_description::FormatItem; use time::macros::format_description; use time::{OffsetDateTime, PrimitiveDateTime}; const ALERT_FORMAT: &[FormatItem<'_>] = format_description!("[weekday repr:short], [day].[month].[year], [hour]:[minute]"); const ALERTS_FORMAT: &[FormatItem<'_>] = format_description!( "[day].[month].[year] [hour]:[minute]:[second].[subsecond] [offset_hour sign:mandatory][offset_minute]" ); pub fn deserialize_alert<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, { let s: &str = Deserialize::deserialize(deserializer)?; PrimitiveDateTime::parse(s, ALERT_FORMAT).map_err(serde::de::Error::custom) } pub fn deserialize_alerts<'de, D>(deserializer: D) -> Result where D: Deserializer<'de>, { let s: &str = Deserialize::deserialize(deserializer)?; OffsetDateTime::parse(s, ALERTS_FORMAT).map_err(serde::de::Error::custom) }