|null * @throws Exception */ public static function recurrence(array $args, $timezone = null) { // Get Recurrence Template [ 'freq' => $freq, 'start' => $start, 'interval' => $interval, 'minutes' => $minutes, 'hours' => $hours, 'monthdays' => $monthdays, 'days' => $days, 'months' => $months, 'setpos' => $setpos, 'finish_method' => $finish_method, 'count' => $count, 'until' => $until ] = Template::apply($args); // Not Supported if (!in_array($freq, ['minutely', 'hourly', 'daily', 'weekly', 'monthly', 'yearly'])) return null; // Timezone if ($timezone) { $start = (new DateTime($start, $timezone)); if ($until) $until = (new DateTime($until, $timezone)); } $rules = [ 'FREQ' => $freq, 'DTSTART' => $start, 'INTERVAL' => $interval, 'BYMONTH' => $months, 'BYMONTHDAY' => $monthdays, 'BYDAY' => $days, 'BYHOUR' => $hours, 'BYMINUTE' => $minutes, 'BYSETPOS' => $setpos, 'WKST' => Weekdays::start(), ]; if ($finish_method === 'count') $rules['COUNT'] = $count; else $rules['UNTIL'] = $until; return new Recurrence($rules); } /** * This function returns the sessions in UTC. * You may need to convert it to proper timezone. * * @param string $rule * @return Recurrence */ public static function recurrenceByRFCString(string $rule) { return new Recurrence($rule); } }