Skip to content

Commit aeccb21

Browse files
committed
Fix yet unsupported "RDATE before DTSTART". This has to be supported.
RDATE is an execption. We do not have control over the point in time where the exception is scheduled and hence should not assume that is is always after DTSTART.
1 parent cfb111f commit aeccb21

2 files changed

Lines changed: 12 additions & 10 deletions

File tree

lib/Recur/EventIterator.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,6 @@ public function __construct($input, ?string $uid = null, ?\DateTimeZone $timeZon
164164
}
165165

166166
$this->recurIterators = [];
167-
$isRecurring = false;
168167
if (isset($this->masterEvent->RRULE)) {
169168
foreach ($this->masterEvent->RRULE as $rRule) {
170169
$this->recurIterators[] = new RRuleIterator(
@@ -179,12 +178,10 @@ public function __construct($input, ?string $uid = null, ?\DateTimeZone $timeZon
179178
$this->recurIterators[] = new RDateIterator(
180179
$rDate->getParts(),
181180
$this->startDate,
182-
omitStart: $isRecurring
183181
);
184-
$isRecurring = true;
185182
}
186183
}
187-
if (!$isRecurring) {
184+
if (empty($this->recurIterators)) {
188185
$this->recurIterators[] = new RRuleIterator(
189186
[
190187
'FREQ' => 'DAILY',

lib/Recur/RDateIterator.php

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class RDateIterator implements \Iterator
2525
*
2626
* @param string|array $rrule
2727
*/
28-
public function __construct($rrule, \DateTimeInterface $start, bool $omitStart = false)
28+
public function __construct($rrule, \DateTimeInterface $start)
2929
{
3030
$this->startDate = $start;
3131
$this->parseRDate($rrule);
32-
if (!$omitStart) {
33-
array_unshift($this->dates, \DateTimeImmutable::createFromInterface($this->startDate));
34-
}
32+
array_unshift($this->dates, \DateTimeImmutable::createFromInterface($this->startDate));
33+
sort($this->dates);
34+
$this->dates = array_values($this->dates);
3535
$this->rewind();
3636
}
3737

@@ -142,8 +142,13 @@ protected function parseRDate($rdate)
142142
if (is_string($rdate)) {
143143
$rdate = explode(',', $rdate);
144144
}
145-
146-
$this->dates = $rdate;
145+
$this->dates = array_map(
146+
fn(string $dateString) => DateTimeParser::parse(
147+
$dateString,
148+
$this->startDate->getTimezone()
149+
),
150+
$rdate
151+
);
147152
}
148153

149154
/**

0 commit comments

Comments
 (0)