From e8b5ea4b1492ff304cbef497c93e1b3ea0b7ee27 Mon Sep 17 00:00:00 2001 From: Jair Cueva Junior Date: Wed, 10 Feb 2021 16:12:39 -0300 Subject: [PATCH 1/6] Make use of until parameter in nextMonthly function --- lib/Recur/RRuleIterator.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index 981260606..2ba2d8369 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -466,7 +466,15 @@ protected function nextMonthly() // This goes to 0 because we need to start counting at the // beginning. - $currentDayOfMonth = 0; + $currentDayOfMonth = 0; + + // For some reason the "until" parameter was not being taken into + // account, that's why the workaround of the 10000 year bug was + // needed at all. + // Let's stop it before the "until" parameter date arrives. + if ($this->currentDate->getTimestamp() >= $this->until->getTimestamp()){ + return; + } // To prevent running this forever (better: until we hit the max date of DateTimeImmutable) we simply // stop at 9999-12-31. Looks like the year 10000 problem is not solved in php .... @@ -475,7 +483,7 @@ protected function nextMonthly() return; } - } + } $this->currentDate = $this->currentDate->setDate( (int) $this->currentDate->format('Y'), From 6c263cea300918245e12d6a2a420b893a0492c42 Mon Sep 17 00:00:00 2001 From: Jair Cueva Junior Date: Wed, 10 Feb 2021 16:27:06 -0300 Subject: [PATCH 2/6] CS FIX --- lib/Recur/RRuleIterator.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index 2ba2d8369..abc0e0a80 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -466,13 +466,12 @@ protected function nextMonthly() // This goes to 0 because we need to start counting at the // beginning. - $currentDayOfMonth = 0; + $currentDayOfMonth = 0; - // For some reason the "until" parameter was not being taken into - // account, that's why the workaround of the 10000 year bug was - // needed at all. - // Let's stop it before the "until" parameter date arrives. - if ($this->currentDate->getTimestamp() >= $this->until->getTimestamp()){ + // For some reason the "until" parameter was not being used here, + // that's why the workaround of the 10000 year bug was needed at all + // let's stop it before the "until" parameter date + if ($this->currentDate->getTimestamp() >= $this->until->getTimestamp()) { return; } @@ -483,7 +482,7 @@ protected function nextMonthly() return; } - } + } $this->currentDate = $this->currentDate->setDate( (int) $this->currentDate->format('Y'), @@ -884,7 +883,7 @@ protected function getMonthlyOccurrences() foreach ($this->byMonthDay as $monthDay) { // Removing values that are out of range for this month if ($monthDay > $startDate->format('t') || - $monthDay < 0 - $startDate->format('t')) { + $monthDay < 0 - $startDate->format('t')) { continue; } if ($monthDay > 0) { @@ -978,3 +977,4 @@ protected function getMonths() return $recurrenceMonths; } } + From 1f2e2e5495172149939ca2ce054c71673c07cbae Mon Sep 17 00:00:00 2001 From: Jair Cueva Junior Date: Wed, 10 Feb 2021 16:35:10 -0300 Subject: [PATCH 3/6] CS FIX --- lib/Recur/RRuleIterator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index abc0e0a80..9c2aecabe 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -977,4 +977,3 @@ protected function getMonths() return $recurrenceMonths; } } - From 6d3f4ee783ac51f76019f622841e75d808639c01 Mon Sep 17 00:00:00 2001 From: Jair Cueva Junior Date: Wed, 10 Feb 2021 17:18:10 -0300 Subject: [PATCH 4/6] Fix breaking tests --- lib/Recur/RRuleIterator.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index 9c2aecabe..0511f0ade 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -471,7 +471,7 @@ protected function nextMonthly() // For some reason the "until" parameter was not being used here, // that's why the workaround of the 10000 year bug was needed at all // let's stop it before the "until" parameter date - if ($this->currentDate->getTimestamp() >= $this->until->getTimestamp()) { + if ($this->until && $this->currentDate->getTimestamp() >= $this->until->getTimestamp()) { return; } From 1bed299d6ac62ac64175eefd8a5ff6b2a64098e9 Mon Sep 17 00:00:00 2001 From: Jair Cueva Junior Date: Thu, 11 Feb 2021 11:43:59 -0300 Subject: [PATCH 5/6] create testMonthlyByDayUntil --- tests/VObject/Recur/RRuleIteratorTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/VObject/Recur/RRuleIteratorTest.php b/tests/VObject/Recur/RRuleIteratorTest.php index f778afb4b..caf921833 100644 --- a/tests/VObject/Recur/RRuleIteratorTest.php +++ b/tests/VObject/Recur/RRuleIteratorTest.php @@ -332,6 +332,22 @@ public function testMonthlyByDay() ); } + public function testMonthlyByDayUntil() + { + $this->parse( + 'FREQ=MONTHLY;INTERVAL=1;BYDAY=WE;WKST=WE;UNTIL=20210317T000000Z', + '2021-02-10 00:00:00', + [ + '2021-02-10 00:00:00', + '2021-02-17 00:00:00', + '2021-02-24 00:00:00', + '2021-03-03 00:00:00', + '2021-03-10 00:00:00', + '2021-03-17 00:00:00', + ] + ); + } + public function testMonthlyByDayByMonthDay() { $this->parse( From 1bbae6556e9c10fc4bc916d5081f8cc1caba5a84 Mon Sep 17 00:00:00 2001 From: Jair Cueva Junior Date: Thu, 11 Feb 2021 11:49:17 -0300 Subject: [PATCH 6/6] create testMonthlyByDayUntilWithImpossibleNextOccurrence --- tests/VObject/Recur/RRuleIteratorTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tests/VObject/Recur/RRuleIteratorTest.php b/tests/VObject/Recur/RRuleIteratorTest.php index caf921833..cc40a6f6f 100644 --- a/tests/VObject/Recur/RRuleIteratorTest.php +++ b/tests/VObject/Recur/RRuleIteratorTest.php @@ -348,6 +348,17 @@ public function testMonthlyByDayUntil() ); } + public function testMonthlyByDayUntilWithImpossibleNextOccurrence() + { + $this->parse( + 'FREQ=MONTHLY;INTERVAL=1;BYDAY=2WE;BYMONTHDAY=2;WKST=WE;UNTIL=20210317T000000Z', + '2021-02-10 00:00:00', + [ + '2021-02-10 00:00:00', + ] + ); + } + public function testMonthlyByDayByMonthDay() { $this->parse(