pub(crate) mod timestamp { use chrono::{DateTime, Utc, TimeZone}; use serde::{self, Deserialize, Serializer, Deserializer}; pub fn serialize( date: &DateTime, serializer: S, ) -> Result where S: Serializer, { serializer.serialize_i64(date.timestamp()) } pub fn deserialize<'de, D>( deserializer: D, ) -> Result, D::Error> where D: Deserializer<'de>, { let timestamp = i64::deserialize(deserializer)?; Ok(Utc.timestamp(timestamp, 0)) } } pub(crate) mod timestamp_opt { use chrono::{DateTime, Utc, TimeZone}; use serde::{self, Deserialize, Serializer, Deserializer}; pub fn serialize( date: &Option>, serializer: S, ) -> Result where S: Serializer, { match date { Some(date) => serializer.serialize_i64(date.timestamp()), None => serializer.serialize_none(), } } pub fn deserialize<'de, D>( deserializer: D, ) -> Result>, D::Error> where D: Deserializer<'de>, { match Option::::deserialize(deserializer)? { Some(timestamp) => Ok(Some(Utc.timestamp(timestamp, 0))), None => Ok(None) } } }