33 lines
828 B
Rust
33 lines
828 B
Rust
use serde::{Deserialize, Serialize, Serializer};
|
|
|
|
#[derive(Debug, Copy, Clone, Deserialize)]
|
|
#[serde(transparent)]
|
|
pub struct DateTime(chrono::DateTime<chrono::Utc>);
|
|
|
|
impl Serialize for DateTime {
|
|
fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
|
|
serializer.serialize_str(&self.to_string())
|
|
}
|
|
}
|
|
|
|
impl Default for DateTime {
|
|
fn default() -> Self {
|
|
chrono::Utc::now().into()
|
|
}
|
|
}
|
|
|
|
impl std::fmt::Display for DateTime {
|
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
|
write!(
|
|
f,
|
|
"{}",
|
|
self.0.to_rfc3339_opts(chrono::SecondsFormat::Secs, true,)
|
|
)
|
|
}
|
|
}
|
|
|
|
impl From<chrono::DateTime<chrono::Utc>> for DateTime {
|
|
fn from(dt: chrono::DateTime<chrono::Utc>) -> Self {
|
|
Self(dt)
|
|
}
|
|
}
|