Make recurrent events preserve weekday across years

This commit is contained in:
Matteo Settenvini 2022-07-29 22:56:17 +02:00
parent 77404d1642
commit 7529556ea6
Signed by: matteo
GPG key ID: 8576CC1AD97D42DF
2 changed files with 224 additions and 217 deletions

View file

@ -3,7 +3,7 @@
use {
crate::recipe::Recipe,
chrono::{DateTime, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc},
chrono::{DateTime, Datelike, Local, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc},
ics::escape_text,
ics::properties as calprop,
ics::Event as CalEvent,
@ -71,7 +71,14 @@ impl<'a> From<Event> for CalEvent<'a> {
event.push(dtend);
// TODO make configurable yearly repetition, for now this suits my personal uses
event.push(calprop::RRule::new("FREQ=YEARLY"));
const DAY_NAMES: [&str; 7] = ["MO", "TU", "WE", "TH", "FR", "SA", "SU"];
event.push(calprop::RRule::new(format!(
"FREQ=YEARLY;BYDAY={weekday};BYWEEKNO={weekno}",
weekday = DAY_NAMES
.get(start_time.weekday().num_days_from_monday() as usize)
.unwrap(),
weekno = start_time.iso_week().week(),
)));
let mut trigger = calprop::Trigger::new("-PT15M");
trigger.append(ics::parameters!("RELATED" => "START"));