You are here

function date_ical_parse_rrule in Date 7.3

Same name and namespace in other branches
  1. 5.2 date_api_ical.inc \date_ical_parse_rrule()
  2. 6.2 date_api_ical.inc \date_ical_parse_rrule()
  3. 6 date_api_ical.inc \date_ical_parse_rrule()
  4. 7 date_api/date_api_ical.inc \date_ical_parse_rrule()
  5. 7.2 date_api/date_api_ical.inc \date_ical_parse_rrule()

Parse an ical repeat rule.

Return value

array A nested array in the form of 'PROPERTY' => array(VALUES) where 'PROPERTIES' includes 'FREQ', 'INTERVAL', 'COUNT', 'BYDAY', 'BYMONTH', 'BYYEAR', 'UNTIL'.

5 calls to date_ical_parse_rrule()
DateMigrateFieldHandler::prepare in ./date.migrate.inc
Converts incoming data into the proper field arrays for Date fields.
date_ical_parse in date_api/date_api_ical.inc
Returns an array of iCalendar information from an iCalendar file.
date_repeat_build_dates in date_repeat_field/date_repeat_field.module
Helper function to build repeating dates from a $node_field.
date_repeat_split_rrule in date_repeat/date_repeat.module
Parse an iCal rule into a parsed RRULE array and an EXDATE array.
_date_repeat_calc in date_repeat/date_repeat_calc.inc
Private implementation of date_repeat_calc().

File

date_api/date_api_ical.inc, line 467
Parse iCal data.

Code

function date_ical_parse_rrule($field, $data) {
  $data = preg_replace("/RRULE.*:/", '', $data);
  $items = array(
    'DATA' => $data,
  );
  $rrule = explode(';', $data);
  foreach ($rrule as $key => $value) {
    $param = explode('=', $value);

    // Must be some kind of invalid data.
    if (count($param) != 2) {
      continue;
    }
    if ($param[0] == 'UNTIL') {
      $values = date_ical_parse_date('', $param[1]);
    }
    else {
      $values = explode(',', $param[1]);
    }

    // Treat items differently if they have multiple or single values.
    if (in_array($param[0], array(
      'FREQ',
      'INTERVAL',
      'COUNT',
      'WKST',
    ))) {
      $items[$param[0]] = $param[1];
    }
    else {
      $items[$param[0]] = $values;
    }
  }
  return $items;
}