mylloon.fr/src/misc/date.rs
Mylloon 2c0fe8d6e5
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
meta: cleanup
* move date to utils dir
* rename get_* to build_*
* increase index ttl from 60 to 120
* split index blog build in half
2023-04-20 15:43:25 +02:00

29 lines
772 B
Rust

use chrono::{Datelike, NaiveDate};
use ramhorns::Content;
use serde::{Deserialize, Deserializer};
#[derive(Content, Default)]
pub struct Date {
pub day: u32,
pub month: u32,
pub year: i32,
}
impl<'de> Deserialize<'de> for Date {
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where
D: Deserializer<'de>,
{
match <&str>::deserialize(deserializer) {
Ok(s) => match NaiveDate::parse_from_str(s, "%d-%m-%Y") {
Ok(date) => Ok(Self {
day: date.day(),
month: date.month(),
year: date.year(),
}),
Err(e) => Err(serde::de::Error::custom(e)),
},
Err(e) => Err(e),
}
}
}