From 9ce978cc321e8403772a0336900ae2b807f8498f Mon Sep 17 00:00:00 2001 From: Samuel Cormier-Iijima Date: Fri, 22 Mar 2024 10:44:54 -0400 Subject: [PATCH] Fix invalid occurrences for BYDAY rrules Fixes #104 --- rrule/src/iter/counter_date.rs | 3 ++- rrule/src/tests/rrule.rs | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/rrule/src/iter/counter_date.rs b/rrule/src/iter/counter_date.rs index b704ee9..621fce3 100644 --- a/rrule/src/iter/counter_date.rs +++ b/rrule/src/iter/counter_date.rs @@ -76,7 +76,8 @@ impl DateTimeIter { self.month = 12; year_div -= 1; } - self.increment_yearly(year_div)?; + self.year += i32::from(year_div); + checks::check_year_range(self.year)?; } Ok(()) } diff --git a/rrule/src/tests/rrule.rs b/rrule/src/tests/rrule.rs index 3581f8e..5d491d3 100644 --- a/rrule/src/tests/rrule.rs +++ b/rrule/src/tests/rrule.rs @@ -1169,6 +1169,27 @@ fn monthly_by_nweekday_large() { ); } +#[test] +fn issue_104() { + let rrule = RRule { + freq: Frequency::Monthly, + interval: 2, + count: Some(3), + by_weekday: vec![NWeekday::Nth(-1, Weekday::Mon)], + ..Default::default() + }; + test_recurring_rrule( + rrule, + true, + ymd_hms(2023, 10, 30, 9, 0, 0), + &[ + ymd_hms(2023, 10, 30, 9, 0, 0), + ymd_hms(2023, 12, 25, 9, 0, 0), + ymd_hms(2024, 2, 26, 9, 0, 0), + ], + ); +} + #[test] fn monthly_by_month_and_weekday() { let rrule = RRule {