diff --git a/lib/Recur/RRuleIterator.php b/lib/Recur/RRuleIterator.php index 0a8f9bcdc..0cd1c0356 100644 --- a/lib/Recur/RRuleIterator.php +++ b/lib/Recur/RRuleIterator.php @@ -787,7 +787,10 @@ protected function getMonthlyOccurrences() { } else { // if it was negative we count from the end of the array - $byDayResults[] = $dayHits[count($dayHits) + $offset]; + // might not exist, fx. -5th tuesday + if (isset($dayHits[count($dayHits) + $offset])) { + $byDayResults[] = $dayHits[count($dayHits) + $offset]; + } } } else { // There was no counter (first, second, last wednesdays), so we diff --git a/tests/VObject/Recur/RRuleIteratorTest.php b/tests/VObject/Recur/RRuleIteratorTest.php index 8299002b0..912293486 100644 --- a/tests/VObject/Recur/RRuleIteratorTest.php +++ b/tests/VObject/Recur/RRuleIteratorTest.php @@ -627,6 +627,21 @@ function testIgnoredStuff() { } + function testMinusFifthThursday() { + + $this->parse( + 'FREQ=MONTHLY;BYDAY=-4TH,-5TH;COUNT=4', + '2015-01-01 00:15:00', + array( + '2015-01-01 00:15:00', + '2015-01-08 00:15:00', + '2015-02-05 00:15:00', + '2015-03-05 00:15:00' + ) + ); + + } + /** * @expectedException InvalidArgumentException */