You are here

function theme_date_formatter in Date 5

Theme date formatter.

Parameters

$dates = an array of the field From and To date objects, as created by date_field_object().: @param $field = the field settings @param $node = node information, this is not always available and not always the full node, it depends on what value was provided to the formatter. Only the nid is always guaranteed to be available.

Useful values: $field['type_name'] - the content type $field['type'] - the field type $node->nid - the node nid, get other node values using node_load($node->nid) $dates['value']['object']->local->timestamp - the local timestamp for the From date $dates['value2']['object']->local->timestamp - the local timestamp for the To date $dates['value']['object']->db->timestamp - the timestamp of the From date database (GMT) value $dates['value2']['object']->db->timestamp - the timestamp of the To date database (GMT) value

1 theme call to theme_date_formatter()
date_field_formatter in ./date.module
Implementation of hook_field_formatter().

File

./date.module, line 719
Defines a date/time field type.

Code

function theme_date_formatter($dates, $field, $formatter, $node) {
  include_once drupal_get_path('module', 'date_api') . '/date.inc';

  // Most formats will be applied to the local value of the date,
  // but use this value to identify those that should format the db part instead.
  $format_db_type = 'local';
  switch (strtolower($formatter)) {
    case 'format_interval':

      // Format interval has its own theme.
      return theme('date_format_interval', $field, $dates, $node);
    case 'timestamp':
      $format = '';
      break;
    case 'long':
      $format = $field['output_format_custom_long'] > '' ? $field['output_format_custom_long'] : ($field['output_format_date_long'] ? $field['output_format_date_long'] : variable_get('date_format_long', 'l, F j, Y - H:i'));
      $format = date_strip_granularity($format, date_granularity_array($field));
      break;
    case 'medium':
      $format = $field['output_format_custom_medium'] > '' ? $field['output_format_custom_medium'] : ($field['output_format_date_medium'] ? $field['output_format_date_medium'] : variable_get('date_format_medium', 'D, m/d/Y - H:i'));
      $format = date_strip_granularity($format, date_granularity_array($field));
      break;
    case 'short':
      $format = $field['output_format_custom_short'] > '' ? $field['output_format_custom_short'] : ($field['output_format_date_short'] ? $field['output_format_date_short'] : variable_get('date_format_short', 'm/d/Y - H:i'));
      $format = date_strip_granularity($format, date_granularity_array($field));
      break;
    case 'iso':
      $format = DATE_STRING_ISO . 'P';
      break;
    case 'feed':
      $format = 'D, j M Y H:i:s O';
      break;
    case 'ical':

      // for ical, send the db value with Z appended to indicate it is the gmt value
      $format = 'Ymd\\THis';
      $append = 'Z';
      $format_db_type = 'db';
      $field['tz_handling'] == 'none';
      break;
    default:
      $format = $field['output_format_custom'] > '' ? $field['output_format_custom'] : ($field['output_format_date'] ? $field['output_format_date'] : variable_get('date_format_short', 'm/d/Y - H:i'));
      $format = date_strip_granularity($format, date_granularity_array($field));
      break;
  }

  // Iterate through the From and To dates to format them, using the format selected above.
  if ($field['todate']) {
    $process = array(
      'value',
      'value2',
    );
  }
  else {
    $process = array(
      'value',
    );
  }
  foreach ($process as $processed) {
    $date = $dates[$processed]['object'];
    if (empty($date->{$format_db_type})) {
      $dates[$processed]['formatted'] = NULL;
    }
    else {
      switch ($formatter) {
        case 'timestamp':
          $dates[$processed]['formatted'] = $date->local->timestamp;
          break;
        default:
          $dates[$processed]['formatted'] = date_format_item($date, $format, $format_db_type, $append);
      }
    }
  }

  // Pass the date object with the formatted dates to the date_display_combination() theme.
  return theme('date_display_combination', $field, $dates, $node);
}