use chrono for day of week labels

move `window::get_sunday` to `time::get_calender_first`
This commit is contained in:
PixelDots 2023-10-23 13:34:19 -05:00 committed by Ashley Wulber
parent ee73884b07
commit e5f135a76e
3 changed files with 17 additions and 10 deletions

View file

@ -0,0 +1,8 @@
use chrono::{Datelike, Days, NaiveDate, Weekday};
/// Gets the first date that will be visible on the calender
pub fn get_calender_first(year: i32, month: u32, from_weekday: Weekday) -> NaiveDate {
let date = NaiveDate::from_ymd_opt(year, month, 1).unwrap();
let num_days = (date.weekday() as u32 + 7 - from_weekday as u32) % 7; // chrono::Weekday.num_days_from
date.checked_sub_days(Days::new(num_days as u64)).unwrap()
}