public function RlHelper::generateOccurrences in Recurring Dates Field 3.x
Same name and namespace in other branches
- 8.2 src/Rl/RlHelper.php \Drupal\date_recur\Rl\RlHelper::generateOccurrences()
- 3.0.x src/Rl/RlHelper.php \Drupal\date_recur\Rl\RlHelper::generateOccurrences()
- 3.1.x src/Rl/RlHelper.php \Drupal\date_recur\Rl\RlHelper::generateOccurrences()
Calculates occurrences as a generator.
Parameters
\DateTimeInterface|null $rangeStart: The start of the range, or start with the first available occurrence.
\DateTimeInterface|null $rangeEnd: The end of the range, or never end.
Return value
\Generator|\Drupal\date_recur\DateRange[] A date range generator.
Overrides DateRecurHelperInterface::generateOccurrences
1 call to RlHelper::generateOccurrences()
- RlHelper::getOccurrences in src/
Rl/ RlHelper.php - Get all occurrences.
File
- src/
Rl/ RlHelper.php, line 152
Class
- RlHelper
- Helper for recurring rules implemented with rlanvin/rrule.
Namespace
Drupal\date_recur\RlCode
public function generateOccurrences(?\DateTimeInterface $rangeStart = NULL, ?\DateTimeInterface $rangeEnd = NULL) : \Generator {
foreach ($this->set as $occurrenceStart) {
/** @var \DateTime $occurrence */
$occurrenceEnd = clone $occurrenceStart;
$occurrenceEnd
->add($this->recurDiff);
if ($rangeStart) {
if ($occurrenceStart < $rangeStart && $occurrenceEnd < $rangeStart) {
continue;
}
}
if ($rangeEnd) {
if ($occurrenceStart > $rangeEnd && $occurrenceEnd > $rangeEnd) {
break;
}
}
(yield new DateRange($occurrenceStart, $occurrenceEnd));
}
}