You are here

function theme_commons_events_date_display_range_advanced in Drupal Commons 7.3

Returns specific HTML for a date element formatted with the event formatter.

We parse the date segments and return it at the bottom, or use the simple formatter (above) if parts of the date are too complicated.

1 string reference to 'theme_commons_events_date_display_range_advanced'
commons_events_theme_registry_alter in modules/commons/commons_events/commons_events.module
Implements hook_theme_registry_alter(). Gives us the ability to insert our pretty date formatter for the dates we choose below.

File

modules/commons/commons_events/commons_events.module, line 569

Code

function theme_commons_events_date_display_range_advanced($variables) {
  $timezone = $variables['timezone'];
  $attributes_start = $variables['attributes_start'];
  $attributes_end = $variables['attributes_end'];

  // Time is always formatted the same.
  $time1 = $variables['dates']['value']['formatted_time'];
  $time2 = $variables['dates']['value2']['formatted_time'];

  // See date.theme line 168 -- regarding formatting time for same date events.
  if ($variables['dates']['value']['formatted_date'] === $variables['dates']['value2']['formatted_date']) {
    return theme('commons_events_date_display_range_simple', $variables);
  }

  // If the difference is over a year, use the simple formatter.
  if ($variables['dates']['value']['db']['object']
    ->difference($variables['dates']['value2']['db']['object'], 'years') > 0) {
    return theme('commons_events_date_display_range_simple', $variables);
  }
  else {
    if ($variables['dates']['value']['db']['object']
      ->difference($variables['dates']['value2']['db']['object'], 'months') > 0) {
      $variables['dates']['value']['db']['object']
        ->limitGranularity(array(
        'day',
        'month',
      ));
      $variables['dates']['value2']['db']['object']
        ->limitGranularity(array(
        'day',
        'month',
        'year',
      ));
      $date1 = $variables['dates']['value']['db']['object']
        ->format($variables['dates']['format'], FALSE);
      $date2 = $variables['dates']['value2']['db']['object']
        ->format($variables['dates']['format'], FALSE);
    }
    else {
      if ($variables['dates']['value']['db']['object']
        ->difference($variables['dates']['value2']['db']['object'], 'days') > 0) {

        // If the Day is before the month (Europe, etc) then switch the granularity.
        if (strpos($variables['dates']['format'], 'M') != 0 || strpos($variables['dates']['format'], 'm') != 0 || strpos($variables['dates']['format'], 'F') != 0 || strpos($variables['dates']['format'], 'n') != 0) {
          $variables['dates']['value']['db']['object']
            ->limitGranularity(array(
            'day',
          ));
          $variables['dates']['value2']['db']['object']
            ->limitGranularity(array(
            'day',
            'month',
            'year',
          ));
        }
        else {
          $variables['dates']['value']['db']['object']
            ->limitGranularity(array(
            'month',
            'day',
          ));
          $variables['dates']['value2']['db']['object']
            ->limitGranularity(array(
            'day',
            'year',
          ));
        }
        $date1 = $variables['dates']['value']['db']['object']
          ->format($variables['dates']['format'], FALSE);
        $date2 = $variables['dates']['value2']['db']['object']
          ->format($variables['dates']['format'], FALSE);

        // If we are match 'D' or 'l', then we have a 'day' in there (eg Monday),
        // we want the whole date because it looks funky otherwise.
        if (strpbrk($variables['dates']['format'], 'Dl')) {
          return theme('commons_events_date_display_range_simple', $variables);
        }
      }
      else {
        return theme('commons_events_date_display_range_simple', $variables);
      }
    }
  }

  // Wrap the result with the attributes.
  return t('!start-date to !end-date, !start-time - !end-time', array(
    '!start-date' => '<span class="date-display-start"' . drupal_attributes($attributes_start) . '>' . $date1 . '</span>',
    '!end-date' => '<span class="date-display-end"' . drupal_attributes($attributes_end) . '>' . $date2 . '</span>',
    '!start-time' => '<span class="date-display-start"' . drupal_attributes($attributes_start) . '>' . $time1 . '</span>',
    '!end-time' => '<span class="date-display-end"' . drupal_attributes($attributes_end) . '>' . $time2 . $timezone . '</span>',
  ));
}