From 2a725a1a9094b408ea11494f7a5d062dc5b1af18 Mon Sep 17 00:00:00 2001 From: Tijmen van Nesselrooij Date: Tue, 16 Sep 2025 16:38:42 +0200 Subject: [PATCH] Add today helper method to YearMonth --- src/shared_api_lib/src/year_month.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/shared_api_lib/src/year_month.rs b/src/shared_api_lib/src/year_month.rs index b86b0c4..820a8b0 100644 --- a/src/shared_api_lib/src/year_month.rs +++ b/src/shared_api_lib/src/year_month.rs @@ -1,3 +1,5 @@ +use chrono::Datelike; + #[derive(Copy, Clone)] pub struct YearMonth { pub year: i32, @@ -39,6 +41,14 @@ impl YearMonth { _ => 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 {