Skip to content

Commit

Permalink
Fix bug in by year day
Browse files Browse the repository at this point in the history
  • Loading branch information
KAYLukas authored and phil-davis committed Aug 17, 2022
1 parent 86d8c52 commit 216e595
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 24 deletions.
7 changes: 4 additions & 3 deletions lib/Recur/RRuleIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -602,11 +602,12 @@ protected function nextYearly()
// loop through all YearDay and Days to check all the combinations
foreach ($this->byYearDay as $byYearDay) {
$date = clone $this->currentDate;
$date = $date->setDate($currentYear, 1, 1);
if ($byYearDay > 0) {
$date = $date->add(new \DateInterval('P'.$byYearDay.'D'));
$date = $date->setDate($currentYear, 1, 1);
$date = $date->add(new \DateInterval('P'.($byYearDay - 1).'D'));
} else {
$date = $date->sub(new \DateInterval('P'.abs($byYearDay).'D'));
$date = $date->setDate($currentYear, 12, 31);
$date = $date->sub(new \DateInterval('P'.abs($byYearDay + 1).'D'));
}

if ($date > $this->currentDate && in_array($date->format('N'), $dayOffsets)) {
Expand Down
59 changes: 38 additions & 21 deletions tests/VObject/Recur/RRuleIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -526,19 +526,36 @@ public function testYearlyByMonthByDay()
);
}

public function testYearlyNewYearsEve()
{
$this->parse(
'FREQ=YEARLY;COUNT=7;INTERVAL=2;BYYEARDAY=1',
'2011-01-01 03:07:00',
[
'2011-01-01 03:07:00',
'2013-01-01 03:07:00',
'2015-01-01 03:07:00',
'2017-01-01 03:07:00',
'2019-01-01 03:07:00',
'2021-01-01 03:07:00',
'2023-01-01 03:07:00',
]
);
}

public function testYearlyByYearDay()
{
$this->parse(
'FREQ=YEARLY;COUNT=7;INTERVAL=2;BYYEARDAY=190',
'2011-07-10 03:07:00',
'2011-07-09 03:07:00',
[
'2011-07-10 03:07:00',
'2013-07-10 03:07:00',
'2015-07-10 03:07:00',
'2017-07-10 03:07:00',
'2019-07-10 03:07:00',
'2021-07-10 03:07:00',
'2023-07-10 03:07:00',
'2011-07-09 03:07:00',
'2013-07-09 03:07:00',
'2015-07-09 03:07:00',
'2017-07-09 03:07:00',
'2019-07-09 03:07:00',
'2021-07-09 03:07:00',
'2023-07-09 03:07:00',
]
);
}
Expand All @@ -559,7 +576,7 @@ public function testYearlyByYearDayImmutable()
$parser->next();

$item = $parser->current();
$this->assertEquals($item->format('Y-m-d H:i:s'), '2013-07-10 03:07:00');
$this->assertEquals($item->format('Y-m-d H:i:s'), '2013-07-09 03:07:00');
}

public function testYearlyByYearDayMultiple()
Expand All @@ -569,13 +586,13 @@ public function testYearlyByYearDayMultiple()
'2011-07-10 14:53:11',
[
'2011-07-10 14:53:11',
'2011-10-29 14:53:11',
'2014-07-10 14:53:11',
'2014-10-29 14:53:11',
'2017-07-10 14:53:11',
'2017-10-29 14:53:11',
'2020-07-09 14:53:11',
'2020-10-28 14:53:11',
'2011-10-28 14:53:11',
'2014-07-09 14:53:11',
'2014-10-28 14:53:11',
'2017-07-09 14:53:11',
'2017-10-28 14:53:11',
'2020-07-08 14:53:11',
'2020-10-27 14:53:11',
]
);
}
Expand All @@ -587,11 +604,11 @@ public function testYearlyByYearDayByDay()
'2001-04-07 14:53:11',
[
'2001-04-07 14:53:11',
'2006-04-08 14:53:11',
'2012-04-07 14:53:11',
'2017-04-08 14:53:11',
'2023-04-08 14:53:11',
'2034-04-08 14:53:11',
'2007-04-07 14:53:11',
'2018-04-07 14:53:11',
'2024-04-06 14:53:11',
'2029-04-07 14:53:11',
'2035-04-07 14:53:11',
]
);
}
Expand Down

0 comments on commit 216e595

Please sign in to comment.