Skip to content

Commit 35f5b55

Browse files
SebastianKrupinskiphil-davis
authored andcommitted
fix: use RDATE in time range check and use all instances
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent c195421 commit 35f5b55

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

lib/Component/VEvent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class VEvent extends VObject\Component
2929
*/
3030
public function isInTimeRange(DateTimeInterface $start, DateTimeInterface $end)
3131
{
32-
if ($this->RRULE) {
32+
if ($this->RRULE || $this->RDATE) {
3333
try {
3434
$it = new EventIterator($this, null, $start->getTimezone());
3535
} catch (NoInstancesException $e) {

lib/Recur/EventIterator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,12 @@ public function __construct($input, $uid = null, ?DateTimeZone $timeZone = null)
168168
}
169169

170170
if (isset($this->masterEvent->RDATE)) {
171+
$rdateValues = [];
172+
foreach ($this->masterEvent->RDATE as $rdate) {
173+
$rdateValues = array_merge($rdateValues, $rdate->getParts());
174+
}
171175
$this->recurIterator = new RDateIterator(
172-
$this->masterEvent->RDATE->getParts(),
176+
$rdateValues,
173177
$this->startDate
174178
);
175179
} elseif (isset($this->masterEvent->RRULE)) {

tests/VObject/Component/VEventTest.php

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,41 @@ public function timeRangeTestData()
8989
$vevent9->RRULE = 'FREQ=DAILY';
9090
$tests[] = [$vevent9, new \DateTime('2016-10-31'), new \DateTime('2016-12-12'), true];
9191

92+
// Added this test to check events with RDATE property with multiple dates
93+
$vevent10 = clone $vevent;
94+
$vevent10->DTSTART = '20140901T000000Z';
95+
$vevent10->DTEND = '20140901T010000Z';
96+
$vevent10->add('RDATE', ['20141001T000000Z', '20141101T000000Z']);
97+
// DTSTART is the first occurrence
98+
$tests[] = [$vevent10, new \DateTime('2014-09-01'), new \DateTime('2014-09-02'), true];
99+
// RDATE adds additional occurrences on Oct 1 and Nov 1
100+
$tests[] = [$vevent10, new \DateTime('2014-10-01'), new \DateTime('2014-10-02'), true];
101+
$tests[] = [$vevent10, new \DateTime('2014-11-01'), new \DateTime('2014-11-02'), true];
102+
// No occurrence in December
103+
$tests[] = [$vevent10, new \DateTime('2014-12-01'), new \DateTime('2014-12-31'), false];
104+
// Range that includes first occurrence
105+
$tests[] = [$vevent10, new \DateTime('2014-08-01'), new \DateTime('2014-09-30'), true];
106+
// Range that spans all occurrences
107+
$tests[] = [$vevent10, new \DateTime('2014-08-01'), new \DateTime('2014-12-31'), true];
108+
109+
// Added this test to check events with RDATE property with multiple instances
110+
$vevent11 = clone $vevent;
111+
$vevent11->DTSTART = '20140901T000000Z';
112+
$vevent11->DTEND = '20140901T010000Z';
113+
$vevent11->add('RDATE', '20141001T000000Z');
114+
$vevent11->add('RDATE', '20141101T000000Z');
115+
// DTSTART is the first occurrence
116+
$tests[] = [$vevent11, new \DateTime('2014-09-01'), new \DateTime('2014-09-02'), true];
117+
// RDATE adds additional occurrences on Oct 1 and Nov 1
118+
$tests[] = [$vevent11, new \DateTime('2014-10-01'), new \DateTime('2014-10-02'), true];
119+
$tests[] = [$vevent11, new \DateTime('2014-11-01'), new \DateTime('2014-11-02'), true];
120+
// No occurrence in December
121+
$tests[] = [$vevent11, new \DateTime('2014-12-01'), new \DateTime('2014-12-31'), false];
122+
// Range that includes first occurrence
123+
$tests[] = [$vevent11, new \DateTime('2014-08-01'), new \DateTime('2014-09-30'), true];
124+
// Range that spans all occurrences
125+
$tests[] = [$vevent11, new \DateTime('2014-08-01'), new \DateTime('2014-12-31'), true];
126+
92127
return $tests;
93128
}
94129
}

0 commit comments

Comments
 (0)