Skip to content

Commit

Permalink
Added test to check for correct solution + reverted partial solution
Browse files Browse the repository at this point in the history
  • Loading branch information
christiaangoossens committed Feb 8, 2023
1 parent e45d68e commit 272251a
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/IcalParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,20 +452,17 @@ public function getEvents(): EventsList {

$firstEvent = true;
foreach ($recurrences as $j => $recurDate) {
if (isset($event['RRULE']['INTERVAL'])) {
if ($event['DTSTART']->diff($recurDate)->format('%a') % $event['RRULE']['INTERVAL'] * 7 == 0) {
$newEvent = $event;
if (!$firstEvent) {
unset($newEvent['RECURRENCES']);
$newEvent['DTSTART'] = $recurDate;
$newEvent['DTEND'] = clone($recurDate);
$newEvent['DTEND']->add($eventInterval);
}
$newEvent['RECURRENCE_INSTANCE'] = $j;
$events->append($newEvent);
$firstEvent = false;
}
$newEvent = $event;
if (!$firstEvent) {
unset($newEvent['RECURRENCES']);
$newEvent['DTSTART'] = $recurDate;
$newEvent['DTEND'] = clone($recurDate);
$newEvent['DTEND']->add($eventInterval);
}

$newEvent['RECURRENCE_INSTANCE'] = $j;
$events->append($newEvent);
$firstEvent = false;
}
}
}
Expand Down
34 changes: 34 additions & 0 deletions tests/cal/rrule_interval.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
X-WR-CALNAME:[email protected]
X-WR-TIMEZONE:America/Los_Angeles
BEGIN:VTIMEZONE
TZID:America/Los_Angeles
X-LIC-LOCATION:America/Los_Angeles
BEGIN:DAYLIGHT
TZOFFSETFROM:-0800
TZOFFSETTO:-0700
TZNAME:PDT
DTSTART:19700308T020000
RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=2SU
END:DAYLIGHT
BEGIN:STANDARD
TZOFFSETFROM:-0700
TZOFFSETTO:-0800
TZNAME:PST
DTSTART:19701101T020000
RRULE:FREQ=YEARLY;BYMONTH=11;BYDAY=1SU
END:STANDARD
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=America/Los_Angeles:20230131T050000
DTEND;TZID=America/Los_Angeles:20230131T060000
RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20230228T090000;INTERVAL=2;BYDAY=TU
DTSTAMP:20120803T221236Z
DESCRIPTION:
SUMMARY:Every day recurring
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR
19 changes: 19 additions & 0 deletions tests/events.recurring.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -239,3 +239,22 @@ test('', function () {
Assert::equal('18.4.2019 09:00:00', $events[38]['DTSTART']->format('j.n.Y H:i:s'));
Assert::equal('19.4.2019 09:00:00', $events[39]['DTSTART']->format('j.n.Y H:i:s'));
});

test('Recurring instances bi-weekly', function () {
// https://github.com/OzzyCzech/icalparser/issues/61
$cal = new IcalParser();

$cal->parseFile(__DIR__ . '/cal/rrule_interval.ics');
$events = $cal->getEvents()->sorted();

var_dump($events[0]['RECURRENCES']);

// DTSTART;TZID=America/Los_Angeles:20230131T050000
// DTEND;TZID=America/Los_Angeles:20230131T060000
// RRULE:FREQ=WEEKLY;WKST=MO;UNTIL=20230228T090000;INTERVAL=2;BYDAY=TU
Assert::equal(3, count($events[0]['RECURRENCES']));
Assert::equal(3, $events->count());
Assert::equal('1.31.2023 5:00:00', $events[0]['DTSTART']->format('j.n.Y H:i:s'));
Assert::equal('2.14.2023 5:00:00', $events[1]['DTSTART']->format('j.n.Y H:i:s'));
Assert::equal('2.28.2023 5:00:00', $events[2]['DTSTART']->format('j.n.Y H:i:s'));
});

0 comments on commit 272251a

Please sign in to comment.