diff options
-rw-r--r-- | src/options.rs | 101 | ||||
-rw-r--r-- | src/rrulestr.rs | 43 | ||||
-rw-r--r-- | tests/rrule.rs | 70 |
3 files changed, 85 insertions, 129 deletions
diff --git a/src/options.rs b/src/options.rs index c3aeff3..67c779e 100644 --- a/src/options.rs +++ b/src/options.rs @@ -46,103 +46,4 @@ pub struct ParsedOptions { pub bysecond: Vec<usize>, pub bynweekday: Vec<Vec<isize>>, pub byeaster: Option<isize>, -} - -impl ParsedOptions { - pub fn new(freq: Frequenzy, dtstart: &DateTime<Utc>) -> 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 isize], - 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], - byeaster: None, - } - } - - 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<Utc>) -> 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<Utc>) -> Self { - self.dtstart = dtstart; - self - } - pub fn wkst(mut self, wkst: usize) -> Self { - self.wkst = wkst; - self - } - pub fn bysetpos(mut self, bysetpos: Vec<isize>) -> Self { - self.bysetpos = bysetpos; - self - } - pub fn bymonth(mut self, bymonth: Vec<usize>) -> Self { - self.bymonth = bymonth; - self - } - pub fn bymonthday(mut self, bymonthday: Vec<isize>) -> Self { - self.bymonthday = bymonthday; - self - } - pub fn bynmonthday(mut self, bynmonthday: Vec<isize>) -> Self { - self.bynmonthday = bynmonthday; - self - } - pub fn byyearday(mut self, byyearday: Vec<isize>) -> Self { - self.byyearday = byyearday; - self - } - pub fn byweekno(mut self, byweekno: Vec<isize>) -> Self { - self.byweekno = byweekno; - self - } - pub fn byweekday(mut self, byweekday: Vec<usize>) -> Self { - self.byweekday = byweekday; - self - } - pub fn bynweekday(mut self, bynweekday: Vec<Vec<isize>>) -> Self { - self.bynweekday = bynweekday; - self - } - pub fn byhour(mut self, byhour: Vec<usize>) -> Self { - self.byhour = byhour; - self - } - pub fn byminute(mut self, byminute: Vec<usize>) -> Self { - self.byminute = byminute; - self - } - pub fn bysecond(mut self, bysecond: Vec<usize>) -> Self { - self.bysecond = bysecond; - self - } -} +}
\ No newline at end of file diff --git a/src/rrulestr.rs b/src/rrulestr.rs index 71cbfe1..4613f8a 100644 --- a/src/rrulestr.rs +++ b/src/rrulestr.rs @@ -489,30 +489,29 @@ fn build_rule(s: &str) -> RRuleSet { mod test { use super::*; - // #[test] - // fn it_works_2() { - // let options = build_rule("DTSTART:19970902T090000Z\nRRULE:FREQ=YEARLY;COUNT=3\n"); - // println!("?????????????=================?????????????"); - // println!("{:?}", options); - // } - - // #[test] - // fn it_works() { - // let options = build_rule("RRULE:UNTIL=19990404T110000Z;DTSTART=19990104T110000Z;FREQ=WEEKLY;BYDAY=TU,WE"); - // println!("?????????????=================?????????????"); - // println!("{:?}", options); - // } - - // #[test] - // fn it_works() { - // let options = build_rule("RRULE:UNTIL=19990404T110000Z;DTSTART;TZID=America/New_York:19990104T110000Z;FREQ=WEEKLY;BYDAY=TU,WE"); - // let parsed_opts = parse_options(&options); - // println!("?????????????=================?????????????"); - // println!("{:?}", options); - // } + #[test] + fn it_works_1() { + let options = build_rule("DTSTART:19970902T090000Z\nRRULE:FREQ=YEARLY;COUNT=3\n"); + println!("?????????????=================?????????????"); + println!("{:?}", options); + } + + #[test] + fn it_works_2() { + let options = build_rule("RRULE:UNTIL=19990404T110000Z;DTSTART=19990104T110000Z;FREQ=WEEKLY;BYDAY=TU,WE"); + println!("?????????????=================?????????????"); + println!("{:?}", options); + } + + #[test] + fn it_works_3() { + let options = build_rule("RRULE:UNTIL=19990404T110000Z;DTSTART;TZID=America/New_York:19990104T110000Z;FREQ=WEEKLY;BYDAY=TU,WE"); + println!("?????????????=================?????????????"); + println!("{:?}", options); + } #[test] - fn it_works() { + fn it_works_4() { let options = parse_string("RRULE:UNTIL=19990404T110000Z;DTSTART;TZID=America/New_York:19990104T110000Z;FREQ=WEEKLY;BYDAY=TU,WE"); let parsed_opts = parse_options(&options); println!("?????????????=================?????????????"); diff --git a/tests/rrule.rs b/tests/rrule.rs index 65aed6c..6365abc 100644 --- a/tests/rrule.rs +++ b/tests/rrule.rs @@ -40,7 +40,27 @@ mod test { #[test] fn yearly() { - let options = ParsedOptions::new(Frequenzy::YEARLY, &ymd_hms(1997, 9, 2, 9, 0, 0)).count(3); + let options = ParsedOptions { + freq: Frequenzy::YEARLY, + count: Some(3), + bymonth: vec![9], + dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), + byweekday: vec![], + byhour: vec![9], + bysetpos: vec![], + byweekno: vec![], + byminute: vec![0], + bysecond: vec![0], + byyearday: vec![], + bymonthday: vec![2], + bynweekday: vec![], + bynmonthday: vec![], + until: None, + wkst: 0, + tzid: None, + interval: 1, + byeaster: None, + }; test_recurring( options, &vec![ @@ -53,9 +73,27 @@ mod test { #[test] fn yearly_interval() { - let options = ParsedOptions::new(Frequenzy::YEARLY, &ymd_hms(1997, 9, 2, 9, 0, 0)) - .count(3) - .interval(2); + let options = ParsedOptions { + freq: Frequenzy::YEARLY, + count: Some(3), + bymonth: vec![9], + dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), + byweekday: vec![], + byhour: vec![9], + bysetpos: vec![], + byweekno: vec![], + byminute: vec![0], + bysecond: vec![0], + byyearday: vec![], + bymonthday: vec![2], + bynweekday: vec![], + bynmonthday: vec![], + until: None, + wkst: 0, + tzid: None, + interval: 2, + byeaster: None, + }; test_recurring( options, &vec![ @@ -68,9 +106,27 @@ mod test { #[test] fn yearly_interval_large() { - let options = ParsedOptions::new(Frequenzy::YEARLY, &ymd_hms(1997, 9, 2, 9, 0, 0)) - .count(3) - .interval(40); + let options = ParsedOptions { + freq: Frequenzy::YEARLY, + count: Some(3), + bymonth: vec![9], + dtstart: ymd_hms(1997, 9, 2, 9, 0, 0), + byweekday: vec![], + byhour: vec![9], + bysetpos: vec![], + byweekno: vec![], + byminute: vec![0], + bysecond: vec![0], + byyearday: vec![], + bymonthday: vec![2], + bynweekday: vec![], + bynmonthday: vec![], + until: None, + wkst: 0, + tzid: None, + interval: 40, + byeaster: None, + }; test_recurring( options, &vec![ |