use chrono for day of week labels
move `window::get_sunday` to `time::get_calender_first`
This commit is contained in:
parent
ee73884b07
commit
e5f135a76e
3 changed files with 17 additions and 10 deletions
8
cosmic-applet-time/src/time.rs
Normal file
8
cosmic-applet-time/src/time.rs
Normal 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()
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue