Add today helper method to YearMonth

This commit is contained in:
2025-09-16 16:38:42 +02:00
parent 84231b5ef7
commit 2a725a1a90

View File

@@ -1,3 +1,5 @@
use chrono::Datelike;
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
pub struct YearMonth { pub struct YearMonth {
pub year: i32, pub year: i32,
@@ -39,6 +41,14 @@ impl YearMonth {
_ => None, _ => None,
} }
} }
pub fn today() -> YearMonth {
let now = chrono::prelude::Local::now();
return YearMonth {
year: now.year(),
month: u8::try_from(now.month()).unwrap(),
};
}
} }
impl std::fmt::Display for YearMonth { impl std::fmt::Display for YearMonth {