You are here

function date_repeat_adjust_rrule in Date 7.2

Same name and namespace in other branches
  1. 5.2 date_repeat/date_repeat_calc.inc \date_repeat_adjust_rrule()
  2. 6.2 date_repeat/date_repeat_calc.inc \date_repeat_adjust_rrule()
  3. 6 date_repeat/date_repeat_calc.inc \date_repeat_adjust_rrule()
  4. 7.3 date_repeat/date_repeat_calc.inc \date_repeat_adjust_rrule()
  5. 7 date_repeat/date_repeat_calc.inc \date_repeat_adjust_rrule()

See if the RRULE needs some imputed values added to it.

1 call to date_repeat_adjust_rrule()
_date_repeat_calc in date_repeat/date_repeat_calc.inc
Private implementation of date_repeat_calc().

File

date_repeat/date_repeat_calc.inc, line 405
Code to compute the dates that match an iCal RRULE.

Code

function date_repeat_adjust_rrule($rrule, $start_date) {

  // If this is not a valid value, do nothing.
  if (empty($rrule) || empty($rrule['FREQ'])) {
    return array();
  }

  // RFC 2445 says if no day or monthday is specified when creating repeats for
  // weeks, months, or years, impute the value from the start date.
  if (empty($rrule['BYDAY']) && $rrule['FREQ'] == 'WEEKLY') {
    $rrule['BYDAY'] = array(
      date_repeat_dow2day(date_format($start_date, 'w')),
    );
  }
  elseif (empty($rrule['BYDAY']) && empty($rrule['BYMONTHDAY']) && $rrule['FREQ'] == 'MONTHLY') {
    $rrule['BYMONTHDAY'] = array(
      date_format($start_date, 'j'),
    );
  }
  elseif (empty($rrule['BYDAY']) && empty($rrule['BYMONTHDAY']) && empty($rrule['BYYEARDAY']) && $rrule['FREQ'] == 'YEARLY') {
    $rrule['BYMONTHDAY'] = array(
      date_format($start_date, 'j'),
    );
    if (empty($rrule['BYMONTH'])) {
      $rrule['BYMONTH'] = array(
        date_format($start_date, 'n'),
      );
    }
  }
  elseif (!empty($rrule['BYDAY']) && !in_array($rrule['FREQ'], array(
    'MONTHLY',
    'YEARLY',
  ))) {
    foreach ($rrule['BYDAY'] as $delta => $by_day) {
      $rrule['BYDAY'][$delta] = substr($by_day, -2);
    }
  }
  return $rrule;
}