You are here

function theme_date_display_interval in Date 8

Same name and namespace in other branches
  1. 7.3 date.theme \theme_date_display_interval()
  2. 7 date.theme \theme_date_display_interval()
  3. 7.2 date.theme \theme_date_display_interval()

Returns HTML for a date element formatted as an interval.

2 theme calls to theme_date_display_interval()
DateFieldFormatIntervalFormatter::viewElements in date_field/lib/Drupal/date_field/Plugin/field/formatter/DateFieldFormatIntervalFormatter.php
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().
FormatIntervalFormatter::viewElements in lib/Drupal/date/Plugin/field/formatter/FormatIntervalFormatter.php
Implements Drupal\field\Plugin\Type\Formatter\FormatterInterface::viewElements().

File

./date.theme, line 288
Theme functions.

Code

function theme_date_display_interval($variables) {
  $entity = $variables['entity'];
  $options = $variables['display']['settings'];
  $dates = $variables['dates'];
  $attributes = $variables['attributes'];

  // Get the formatter settings, either the default settings for this node type
  // or the View settings stored in $entity->date_info.
  if (!empty($entity->date_info) && !empty($entity->date_info->formatter_settings)) {
    $options = $entity->date_info->formatter_settings;
  }
  $time_ago_vars = array(
    'start_date' => $dates['value']['local']['object'],
    'end_date' => $dates['value2']['local']['object'],
    'interval' => $options['interval'],
    'interval_display' => $options['interval_display'],
  );
  if ($return = theme('date_time_ago', $time_ago_vars)) {
    return '<span class="date-display-interval"' . new Attribute($attributes) . ">{$return}</span>";
  }
  else {
    return '';
  }
}