public function DateRRuleCalc::compute in Date 8
File
- date_repeat/lib/Drupal/date_repeat/DateRRuleCalc.php, line 204
- Code to compute the dates that match an iCal RRULE.
Class
- DateRRuleCalc
Namespace
Drupal\date_repeat
Code
public function compute() {
if (!$this
->isValid()) {
return FALSE;
}
if (empty($this->rrule['FREQ'])) {
$this->rrule['FREQ'] = 'DAILY';
}
if ($this->rrule['FREQ'] == 'NONE' || isset($this->rrule['INTERVAL']) && $this->rrule['INTERVAL'] == 0) {
return array();
}
if (empty($this->rrule['INTERVAL'])) {
$this->rrule['INTERVAL'] = 1;
}
$interval = max(1, $this->rrule['INTERVAL']);
if (!empty($this->rrule['BYMONTHDAY']) && !in_array($this->rrule['FREQ'], array(
'MONTHLY',
'YEARLY',
))) {
$this->rrule['FREQ'] = 'MONTHLY';
}
elseif (!empty($this->rrule['BYDAY']) && !in_array($this->rrule['FREQ'], array(
'MONTHLY',
'WEEKLY',
'YEARLY',
))) {
$this->rrule['FREQ'] = 'WEEKLY';
}
switch ($this->rrule['FREQ']) {
case 'DAILY':
$jump_interval = 'P' . $interval . 'D';
break;
case 'WEEKLY':
$jump_interval = 'P' . $interval . 'W';
break;
case 'MONTHLY':
$jump_interval = 'P' . $interval . 'M';
break;
case 'YEARLY':
$jump_interval = 'P' . $interval . 'Y';
break;
}
$this->jump = new \DateInterval($jump_interval);
$this
->complete_rrule();
$this->result[] = date_format($this->start_date, $this->default_format);
if (!empty($this->rrule['BYMONTHDAY'])) {
$this
->get_bymonthday_results();
}
elseif (empty($this->rrule['BYDAY'])) {
$this
->get_other_results();
}
else {
$this
->get_byday_results();
}
foreach ($this->additions as $addition) {
$date = new DrupalDateTime($addition . ' ' . $this->time_string, $this->timezone_name);
$this->result[] = date_format($date, $this->default_format);
}
sort($this->result);
return $this->result;
}