Added .taskrc weekstart value support

This commit is contained in:
Kohlbern Jary 2022-08-23 23:15:45 -04:00
parent 319de81e15
commit fd21ae43c0
3 changed files with 33 additions and 3 deletions

View file

@ -26,6 +26,7 @@ pub struct Calendar<'a> {
pub months_per_row: usize,
pub date_style: Vec<(Date<FixedOffset>, Style)>,
pub today_style: Style,
pub start_on_monday: bool,
pub title_background_color: Color,
}
@ -41,6 +42,7 @@ impl<'a> Default for Calendar<'a> {
month,
date_style: vec![],
today_style: Style::default(),
start_on_monday: false,
title_background_color: Color::Reset,
}
}
@ -84,6 +86,11 @@ impl<'a> Calendar<'a> {
self.months_per_row = months_per_row;
self
}
pub fn start_on_monday(mut self, start_on_monday: bool) -> Self {
self.start_on_monday = start_on_monday;
self
}
}
impl<'a> Widget for Calendar<'a> {
@ -116,9 +123,14 @@ impl<'a> Widget for Calendar<'a> {
.iter()
.map(|i| {
let first = Date::from_utc(NaiveDate::from_ymd(year, i + 1, 1), *Local::now().offset());
let num_days = if self.start_on_monday {
first.weekday().num_days_from_monday()
} else {
first.weekday().num_days_from_sunday()
};
(
first,
first - Duration::days(i64::from(first.weekday().num_days_from_sunday())),
first - Duration::days(i64::from(num_days)),
)
})
.collect();
@ -165,10 +177,15 @@ impl<'a> Widget for Calendar<'a> {
for d in days.iter_mut().take(endm).skip(start_m) {
let m = d.0.month() as usize;
let style = Style::default().bg(self.title_background_color);
let days_string = if self.start_on_monday {
"Mo Tu We Th Fr Sa Su"
} else {
"Su Mo Tu We Th Fr Sa"
};
buf.set_string(
x as u16,
y,
"Su Mo Tu We Th Fr Sa",
days_string,
style.add_modifier(Modifier::UNDERLINED),
);
x += 21 + 1;