Skip to content

Commit

Permalink
Add testcases
Browse files Browse the repository at this point in the history
  • Loading branch information
KAYLukas committed Dec 7, 2018
1 parent a00a460 commit 5f6e97c
Show file tree
Hide file tree
Showing 3 changed files with 451 additions and 16 deletions.
32 changes: 17 additions & 15 deletions lib/Recur/RRuleIterator.php
Expand Up @@ -2,7 +2,6 @@

namespace Sabre\VObject\Recur;

use DateTimeImmutable;
use DateTimeInterface;
use Iterator;
use Sabre\VObject\DateTimeParser;
Expand Down Expand Up @@ -85,26 +84,27 @@ public function rewind()

/**
* Goes on to the next iteration.
*
* @param int $amount
*/
public function next($amount = 1)
{
// Otherwise, we find the next event in the normal RRULE
// sequence.
switch ($this->frequency) {
case 'hourly' :
case 'hourly':
$this->nextHourly($amount);
break;
case 'daily' :
case 'daily':
$this->nextDaily($amount);
break;
case 'weekly' :
case 'weekly':
$this->nextWeekly($amount);
break;
case 'monthly' :
case 'monthly':
$this->nextMonthly($amount);
break;
case 'yearly' :
case 'yearly':
$this->nextYearly($amount);
break;
}
Expand Down Expand Up @@ -135,19 +135,19 @@ public function fastForward(DateTimeInterface $dt)
do {
$diff = $this->currentDate->diff($dt);
switch ($this->frequency) {
case 'hourly' :
case 'hourly':
$i = $diff->days * 24;
break;
case 'daily' :
case 'daily':
$i = $diff->days;
break;
case 'weekly' :
case 'weekly':
$i = $diff->days / 7;
break;
case 'monthly' :
case 'monthly':
$i = $diff->days / 30;
break;
case 'yearly' :
case 'yearly':
$i = $diff->days / 365;
break;
}
Expand Down Expand Up @@ -355,6 +355,7 @@ protected function nextDaily($amount = 1)
{
if (!$this->byHour && !$this->byDay) {
$this->currentDate = $this->currentDate->modify('+'.$amount * $this->interval.' days');

return;
}

Expand Down Expand Up @@ -403,10 +404,12 @@ protected function nextDaily($amount = 1)
/**
* Does the processing for advancing the iterator for weekly frequency.
*/
protected function nextWeekly($amount = 1) {
protected function nextWeekly($amount = 1)
{

if (!$this->byHour && !$this->byDay) {
$this->currentDate = $this->currentDate->modify('+' .($amount * $this->interval).' weeks');
$this->currentDate = $this->currentDate->modify('+'.($amount * $this->interval).' weeks');

return;
}

Expand Down Expand Up @@ -435,7 +438,7 @@ protected function nextWeekly($amount = 1) {
$currentHour = (int) $this->currentDate->format('G');

// We need to roll over to the next week
if ($currentDay === $firstDay && (!$this->byHour || $currentHour == '0')) {
if ($currentDay === $firstDay && (!$this->byHour || '0' == $currentHour)) {
$this->currentDate = $this->currentDate->modify('+'.(($amount * $this->interval) - 1).' weeks');
$amount = 1;
// We need to go to the first day of this week, but only if we
Expand Down Expand Up @@ -596,7 +599,6 @@ protected function nextYearly($amount = 1)

if (count($checkDates) > 0) {
$this->currentDate = min($checkDates);

return;
}

Expand Down

0 comments on commit 5f6e97c

Please sign in to comment.