Add today helper method to YearMonth
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user