You are here

function date_repeat_rrule_description in Date 6

Same name and namespace in other branches
  1. 8 date_repeat/date_repeat.module \date_repeat_rrule_description()
  2. 5.2 date_repeat/date_repeat.module \date_repeat_rrule_description()
  3. 6.2 date_repeat/date_repeat.module \date_repeat_rrule_description()
  4. 7.3 date_repeat/date_repeat.module \date_repeat_rrule_description()
  5. 7 date_repeat/date_repeat.module \date_repeat_rrule_description()
  6. 7.2 date_repeat/date_repeat.module \date_repeat_rrule_description()

Build a description of an iCal rule.

Constructs a human-readable description of the rule.

1 call to date_repeat_rrule_description()
theme_date_repeat_display in date/date.theme
Theme the human-readable description for a Date Repeat rule.

File

date_repeat/date_repeat.module, line 158
This module creates a form element that allows users to select repeat rules for a date, and reworks the result into an iCal RRULE string that can be stored in the database.

Code

function date_repeat_rrule_description($rrule, $start_date, $format = 'D M d Y') {
  include_once drupal_get_path('module', 'date_api') . '/date_api_ical.inc';
  include_once './' . drupal_get_path('module', 'date_repeat') . '/date_repeat_calc.inc';
  $parts = date_repeat_split_rrule($rrule);
  $exceptions = $parts[1];
  $rrule = date_repeat_adjust_rrule($parts[0], $start_date);
  $description = array(
    t('Repeats '),
  );
  if ($rrule['BYDAY']) {
    $days = date_repeat_dow_day_options();
    $counts = date_repeat_dow_count_options();
    $results = array();
    foreach ($rrule['BYDAY'] as $byday) {
      $day = substr($byday, -2);
      if ($count = intval(str_replace(' ' . $day, '', $byday))) {
        $results[] = t('the !count !day ', array(
          '!count' => strtolower($counts[$count]),
          '!day' => $days[$day],
        ));
      }
      else {
        $results[] = t('every !day ', array(
          '!day' => $days[$day],
        ));
      }
    }
    $description[] = t('!days', array(
      '!days' => implode(t(' and '), $results),
    ));
  }
  if ($rrule['BYMONTHDAY']) {
    $description[] = t('day @number', array(
      '@number' => implode(', ', $rrule['BYMONTHDAY']),
    )) . ' ';
  }
  if ($rrule['BYMONTH']) {
    if (sizeof($rrule['BYMONTH']) < 12) {
      $results = array();
      $months = date_month_names();
      foreach ($rrule['BYMONTH'] as $month) {
        $results[] = $months[$month];
      }
      $description[] = implode(', ', $results) . ' ';
    }
  }
  if ($rrule['INTERVAL'] < 1) {
    $rrule['INTERVAL'] = 1;
  }
  $interval = INTERVAL_options();
  switch ($rrule['FREQ']) {
    case 'WEEKLY':
      $description[] = format_plural($rrule['INTERVAL'], t('every week '), t('every @count weeks '));
      break;
    case 'MONTHLY':
      $description[] = format_plural($rrule['INTERVAL'], t('every month '), t('every @count months '));
      break;
    case 'YEARLY':
      $description[] = format_plural($rrule['INTERVAL'], t('every year '), t('every @count years '));
      break;
    default:
      $description[] = format_plural($rrule['INTERVAL'], t('every day '), t('every @count days '));
      break;
  }
  if ($rrule['COUNT']) {
    $description[] = t('for !times occurences ', array(
      '!times' => $rrule['COUNT'],
    ));
  }
  if ($rrule['UNTIL']) {
    $until = date_ical_date($rrule['UNTIL']);
    $description[] = t('until !until ', array(
      '!until' => date_format_date($until, 'custom', $format),
    ));
  }
  if ($exceptions) {
    $values = array();
    foreach ($exceptions as $exception) {
      $values[] = date_format_date(date_ical_date($exception), 'custom', $format);
    }
    $description[] = t('except !dates ', array(
      '!dates' => implode(', ', $values),
    ));
  }
  if ($rrule['WKST']) {
    $day_names = date_repeat_dow_day_options();

    //$description[] = t('where the week starts on !start ', array('!start' => $day_names[$rrule['WKST']]));
  }
  return implode($description);
}