* @implements \IteratorAggregate */ class Recurrence extends BaseRecurrence implements \ArrayAccess, \Countable, \IteratorAggregate { /** * @return \Traversable */ public function getIterator() { return parent::getIterator(); } /** * @param int|null $limit * @return mixed[] */ public function getSessions($limit = null): array { $method = implode('', ['getOccur', 'rences']); return $this->{$method}($limit); } /** * @param mixed $date * @param bool $inclusive * @param int|null $limit * @return mixed[] */ public function getSessionsAfter($date, bool $inclusive = false, $limit = null): array { $method = implode('', ['getOccur', 'rencesAfter']); return $this->{$method}($date, $inclusive, $limit); } /** * @param bool $include_timezone * @return string */ public function rfcString($include_timezone = true): string { // Unset Empty Useless Rules if (Arr::empty($this->rule, 'BYMINUTE')) unset($this->rule['BYMINUTE']); if (Arr::empty($this->rule, 'BYHOUR')) unset($this->rule['BYHOUR']); if (Arr::empty($this->rule, 'BYMONTHDAY')) unset($this->rule['BYMONTHDAY']); if (Arr::empty($this->rule, 'BYDAY')) unset($this->rule['BYDAY']); if (Arr::empty($this->rule, 'BYMONTH')) unset($this->rule['BYMONTH']); if (Arr::empty($this->rule, 'BYSETPOS')) unset($this->rule['BYSETPOS']); return parent::rfcString($include_timezone); } /** * @param bool $include_timezone * @return string */ public function getDTStartRule(bool $include_timezone = true): string { $str = ''; if ($this->rule['DTSTART']) { if (!$include_timezone) $str = sprintf("DTSTART:%s", $this->dtstart->format('Ymd\THis')); else { $dtstart = clone $this->dtstart; $timezone_name = $dtstart->getTimeZone()->getName(); // Handle unsupported timezones like '+02:00' if (strpos($timezone_name,':') !== false) { $dtstart->setTimezone(new DateTimeZone('UTC')); $timezone_name = 'UTC'; } if (in_array($timezone_name, ['UTC','GMT','Z'])) $str = sprintf("DTSTART:%s", $dtstart->format('Ymd\THis\Z')); else $str = sprintf("DTSTART;TZID=%s:%s", $timezone_name, $dtstart->format('Ymd\THis')); } } return $str; } }