Make recurrent events preserve weekday across years
This commit is contained in:
parent
77404d1642
commit
7529556ea6
2 changed files with 224 additions and 217 deletions
11
src/event.rs
11
src/event.rs
|
@ -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"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue