Skip to content

Commit 099a377

Browse files
fix: use RDATE in time range check and use all instances
Signed-off-by: SebastianKrupinski <krupinskis05@gmail.com>
1 parent 3909dc3 commit 099a377

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
@@ -41,7 +41,7 @@ class VEvent extends VObject\Component
4141
*/
4242
public function isInTimeRange(\DateTimeInterface $start, \DateTimeInterface $end): bool
4343
{
44-
if ($this->RRULE) {
44+
if ($this->RRULE || $this->RDATE) {
4545
try {
4646
$it = new EventIterator($this, null, $start->getTimezone());
4747
} catch (NoInstancesException $e) {

lib/Recur/EventIterator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,12 @@ public function __construct($input, ?string $uid = null, ?\DateTimeZone $timeZon
164164
}
165165

166166
if (isset($this->masterEvent->RDATE)) {
167+
$rdateValues = [];
168+
foreach ($this->masterEvent->RDATE as $rdate) {
169+
$rdateValues = array_merge($rdateValues, $rdate->getParts());
170+
}
167171
$this->recurIterator = new RDateIterator(
168-
$this->masterEvent->RDATE->getParts(),
172+
$rdateValues,
169173
$this->startDate
170174
);
171175
} 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(): array
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)