Skip to content

Commit 09253e8

Browse files
committed
Backport of sabre-io#716 -- RDateIterator shoudld not assume that DTSTART is the earliest date.
It should also not assume that the list of dates is sorted at all.
1 parent 88ac2e2 commit 09253e8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

lib/Recur/RDateIterator.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public function __construct($rrule, DateTimeInterface $start)
3232
$this->startDate = $start;
3333
$this->parseRDate($rrule);
3434
array_unshift($this->dates, DateTimeImmutable::createFromInterface($this->startDate));
35+
sort($this->dates);
36+
$this->dates = array_values($this->dates);
3537
$this->rewind();
3638
}
3739

@@ -43,13 +45,6 @@ public function current()
4345
if (!$this->valid()) {
4446
return null;
4547
}
46-
if (is_string($this->dates[$this->counter])) {
47-
$this->dates[$this->counter] =
48-
DateTimeParser::parse(
49-
$this->dates[$this->counter],
50-
$this->startDate->getTimezone()
51-
);
52-
}
5348
return $this->dates[$this->counter];
5449
}
5550

@@ -155,8 +150,13 @@ protected function parseRDate($rdate)
155150
if (is_string($rdate)) {
156151
$rdate = explode(',', $rdate);
157152
}
158-
159-
$this->dates = $rdate;
153+
$this->dates = array_map(
154+
fn(string $dateString) => DateTimeParser::parse(
155+
$dateString,
156+
$this->startDate->getTimezone()
157+
),
158+
$rdate
159+
);
160160
}
161161

162162
/**

0 commit comments

Comments
 (0)