use chrono::prelude::*; #[derive(Debug)] pub struct YearInfo { pub yearlen: usize, pub nextyearlen: usize, pub yearordinal: isize, pub yearweekday: usize, pub mmask: Vec, pub mrange: Vec, pub mdaymask: Vec, pub nmdaymask: Vec, pub wdaymask: Vec, pub wnomask: Option>, } #[derive(Debug, PartialEq, PartialOrd)] pub enum Frequenzy { YEARLY = 0, MONTHLY = 1, WEEKLY = 2, DAILY = 3, HOURLY = 4, MINUTELY = 5, SECONDLY = 6, } #[derive(Debug)] pub struct ParsedOptions { pub freq: Frequenzy, pub interval: usize, pub count: Option, pub until: Option>, pub tzid: Option, pub dtstart: DateTime, pub wkst: usize, pub bysetpos: Vec, pub bymonth: Vec, pub bymonthday: Vec, pub bynmonthday: Vec, pub byyearday: Vec, pub byweekno: Vec, pub byweekday: Vec, pub byhour: Vec, pub byminute: Vec, pub bysecond: Vec, pub bynweekday: Vec>, } impl ParsedOptions { pub fn new(freq: Frequenzy, dtstart: &DateTime) -> Self { Self { freq, interval: 1, count: None, until: None, tzid: None, dtstart: *dtstart, wkst: 0, bysetpos: vec![], bymonth: vec![dtstart.month() as usize], bymonthday: vec![dtstart.day() as usize], bynmonthday: vec![], byyearday: vec![], byweekno: vec![], byweekday: vec![], bynweekday: vec![], byhour: vec![dtstart.hour() as usize], byminute: vec![dtstart.minute() as usize], bysecond: vec![dtstart.second() as usize], } } pub fn freq(mut self, freq: Frequenzy) -> Self { self.freq = freq; self } pub fn interval(mut self, interval: usize) -> Self { self.interval = interval; self } pub fn until(mut self, until: &DateTime) -> Self { self.until = Some(*until); self } pub fn tzid(mut self, tzid: &String) -> Self { self.tzid = Some(tzid.clone()); self } pub fn count(mut self, count: u32) -> Self { self.count = Some(count); self } pub fn dtstart(mut self, dtstart: DateTime) -> Self { self.dtstart = dtstart; self } pub fn wkst(mut self, wkst: usize) -> Self { self.wkst = wkst; self } pub fn bysetpos(mut self, bysetpos: Vec) -> Self { self.bysetpos = bysetpos; self } pub fn bymonth(mut self, bymonth: Vec) -> Self { self.bymonth = bymonth; self } pub fn bymonthday(mut self, bymonthday: Vec) -> Self { self.bymonthday = bymonthday; self } pub fn bynmonthday(mut self, bynmonthday: Vec) -> Self { self.bynmonthday = bynmonthday; self } pub fn byyearday(mut self, byyearday: Vec) -> Self { self.byyearday = byyearday; self } pub fn byweekno(mut self, byweekno: Vec) -> Self { self.byweekno = byweekno; self } pub fn byweekday(mut self, byweekday: Vec) -> Self { self.byweekday = byweekday; self } pub fn bynweekday(mut self, bynweekday: Vec>) -> Self { self.bynweekday = bynweekday; self } pub fn byhour(mut self, byhour: Vec) -> Self { self.byhour = byhour; self } pub fn byminute(mut self, byminute: Vec) -> Self { self.byminute = byminute; self } pub fn bysecond(mut self, bysecond: Vec) -> Self { self.bysecond = bysecond; self } }