You are here

function _date_ical_parse_repeat_rule in Date iCal 7.3

Parse an rrule or exrule string.

Return value

array Array in the form of PROPERTY => array(VALUES) PROPERTIES include FREQ, INTERVAL, COUNT, BYDAY, BYMONTH, BYYEAR, UNTIL.

1 call to _date_ical_parse_repeat_rule()
_date_ical_get_repeat_dates in ./date_ical.utils.inc
Parse the repeat data into date values.

File

./date_ical.utils.inc, line 132
Utility functions for Date iCal. Many of these are re-writes of buggy Date module code.

Code

function _date_ical_parse_repeat_rule($repeat_rule_string) {
  module_load_include('inc', 'date_api', 'date_api_ical');
  $repeat_rule_string = preg_replace('/(R|EX)RULE.*:/', '', $repeat_rule_string);
  $items = array(
    'DATA' => $repeat_rule_string,
  );
  foreach (explode(';', $repeat_rule_string) as $recur_val) {
    list($key, $value) = explode('=', $recur_val);

    // Must be some kind of invalid data.
    if (empty($key) || empty($value)) {
      continue;
    }

    // The following keys never have multiple values.
    if (in_array($key, array(
      'UNTIL',
      'FREQ',
      'INTERVAL',
      'COUNT',
      'WKST',
    ))) {
      if ($key == 'UNTIL') {

        // This is a function from the date_api module, not date_ical.
        $value = date_ical_parse_date('', $value);
      }
    }
    else {

      // The rest can be multi-value csv strings.
      $value = explode(',', $value);
    }
    $items[$key] = $value;
  }
  return $items;
}