You are here

public function _datex_views_handler_field_date::render in Datex 7.3

Render the date, if it should be localized. Otherwise let parent handle it.

Overrides views_handler_field_date::render

File

./datex.views.inc, line 313
Datex views integration.

Class

_datex_views_handler_field_date

Code

public function render($values) {
  $schema = _datex_element_schema($this);
  if (in_array($this->options['date_format'], self::$parent_handled) || $schema === 'disabled') {
    return $this
      ->_sql_or_delegate_render_to_parent($values);
  }
  $value = $this
    ->get_value($values);
  if (!$value) {
    return $this
      ->_sql_or_delegate_render_to_parent($values);
  }
  $tz = empty($this->options['timezone']) ? drupal_get_user_timezone() : $this->options['timezone'];
  $calendar = datex_factory($tz, _datex_language_calendar_name($schema));
  if (!$calendar) {
    return $this
      ->_sql_or_delegate_render_to_parent($values);
  }
  $format = '';
  switch ($this->options['date_format']) {
    case 'short':
      $format = variable_get('date_format_short', 'm/d/Y - H:i');
      break;
    case 'long':
      $format = variable_get('date_format_long', 'l, F j, Y - H:i');
      break;
    case 'custom':
      $format = $this->options['custom_date_format'];
      break;
    case 'medium':
      $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
      break;
    default:
      $format = variable_get('date_format_' . $this->options['date_format'], '');
      break;
  }
  if (empty($format)) {
    $format = variable_get('date_format_medium', 'D, m/d/Y - H:i');
  }
  if ($this
    ->_datex_is_views_date_format_sql()) {
    $en = datex_factory($tz, 'gregorian', 'en');
    if (!$en || !$en
      ->parse($value, $format)) {
      return '?';
    }
    $calendar
      ->setTimestamp($en
      ->getTimestamp());
    return $calendar
      ->format($format);
  }
  else {
    $calendar
      ->setTimestamp($value);
    return $calendar
      ->format($format);
  }
}