summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/iter/mod.rs35
-rw-r--r--src/rrule_iter.rs1
-rw-r--r--src/rrulestr.rs6
3 files changed, 36 insertions, 6 deletions
diff --git a/src/iter/mod.rs b/src/iter/mod.rs
index 5fb439a..efec2ca 100644
--- a/src/iter/mod.rs
+++ b/src/iter/mod.rs
@@ -1,6 +1,7 @@
mod iterinfo;
mod monthinfo;
mod yearinfo;
+
pub use iterinfo::IterInfo;
mod poslist;
pub use poslist::build_poslist;
@@ -13,6 +14,31 @@ use crate::utils::{includes, not_empty};
use chrono::prelude::*;
use chrono::Duration;
+pub fn decrement_date_until_valid(date: DTime, new_month: u32, new_year: Option<i32>) -> DTime {
+ let new_date = if let Some(new_year) = new_year {
+ let mut new_date = date.with_year(new_year);
+ let mut day_i = 1;
+ while new_date.is_none() {
+ new_date = date.with_day(date.day() - day_i);
+ new_date = new_date.unwrap().with_year(new_year);
+ day_i += 1;
+ }
+ new_date.unwrap()
+ } else {
+ date
+ };
+ let mut new_date = new_date.with_month(new_month);
+ let mut day_i = 1;
+ while new_date.is_none() {
+ new_date = date
+ .with_day(date.day() - day_i)
+ .unwrap()
+ .with_month(new_month);
+ day_i += 1;
+ }
+ new_date.unwrap()
+}
+
pub fn increment_counter_date(
counter_date: DTime,
options: &ParsedOptions,
@@ -32,13 +58,10 @@ pub fn increment_counter_date(
year_div -= 1;
}
let new_year = counter_date.year() + year_div as i32;
- counter_date
- .with_month(new_month)
- .unwrap()
- .with_year(new_year)
- .unwrap()
+
+ decrement_date_until_valid(counter_date, new_month, Some(new_year))
} else {
- counter_date.with_month(new_month).unwrap()
+ decrement_date_until_valid(counter_date, new_month, None)
}
}
Frequenzy::Weekly => {
diff --git a/src/rrule_iter.rs b/src/rrule_iter.rs
index 9a4fa8f..6f1af14 100644
--- a/src/rrule_iter.rs
+++ b/src/rrule_iter.rs
@@ -118,6 +118,7 @@ impl RRuleIter {
}
}
+ println!("Buffer: {:?}", self.buffer);
// Handle frequency and interval
self.counter_date = increment_counter_date(self.counter_date, &options, filtered);
diff --git a/src/rrulestr.rs b/src/rrulestr.rs
index ee18199..51a3f24 100644
--- a/src/rrulestr.rs
+++ b/src/rrulestr.rs
@@ -772,4 +772,10 @@ mod test {
assert_eq!(rrule.all().len(), 30);
}
+
+ #[test]
+ fn rrule_all_fails_with_panic() {
+ let res = "DTSTART;VALUE=DATE:20201230T130000\nRRULE:FREQ=MONTHLY;UNTIL=20210825T120000Z;INTERVAL=1;BYDAY=-1WE".parse::<RRuleSet>().unwrap().all();
+ println!("Res {:?}", res);
+ }
}