summaryrefslogtreecommitdiff
path: root/src/rrule_iter.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/rrule_iter.rs')
-rw-r--r--src/rrule_iter.rs23
1 files changed, 22 insertions, 1 deletions
diff --git a/src/rrule_iter.rs b/src/rrule_iter.rs
index 9147b7d..34c4ff3 100644
--- a/src/rrule_iter.rs
+++ b/src/rrule_iter.rs
@@ -6,6 +6,8 @@ use crate::{datetime::Time, Frequenzy};
use chrono::prelude::*;
use chrono_tz::Tz;
+const MAX_YEAR: i32 = 9999;
+
pub struct RRuleIter {
pub counter_date: DateTime<Tz>,
pub ii: IterInfo,
@@ -45,6 +47,10 @@ pub fn generate(iter: &mut RRuleIter) {
_ => (),
};
+ if iter.counter_date.year() > MAX_YEAR {
+ return;
+ }
+
while iter.remain.is_empty() {
let (dayset, start, end) = iter.ii.getdayset(
&iter.ii.options.freq,
@@ -138,7 +144,7 @@ pub fn generate(iter: &mut RRuleIter) {
// Handle frequency and interval
iter.counter_date = increment_counter_date(iter.counter_date, &options, filtered);
- if iter.counter_date.year() > 2200 {
+ if iter.counter_date.year() > MAX_YEAR {
return;
}
@@ -161,6 +167,7 @@ pub fn generate(iter: &mut RRuleIter) {
iter.ii.rebuild(year as isize, month as usize);
}
}
+
impl IntoIterator for RRule {
type Item = DateTime<Tz>;
@@ -182,3 +189,17 @@ impl IntoIterator for RRule {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ #[ignore = "Takes too much time, only run when releasing"]
+ fn iteration_past_max_year_should_not_panic() {
+ let rrule = "DTSTART:20220201T100000Z\nRRULE:FREQ=DAILY"
+ .parse::<RRule>()
+ .unwrap();
+ rrule.clone().into_iter().nth(15000000);
+ }
+}