You are here

function theme_date_all_day in Date 5.2

Same name and namespace in other branches
  1. 8 date_all_day/date_all_day.module \theme_date_all_day()
  2. 6.2 date/date.theme \theme_date_all_day()
  3. 7.3 date_all_day/date_all_day.module \theme_date_all_day()
  4. 7 date.theme \theme_date_all_day()
  5. 7.2 date_all_day/date_all_day.module \theme_date_all_day()

Adjust from/to date format to account for 'all day'.

Parameters

array $field, the field definition for this date field.:

string $which, which value to return, 'date1' or 'date2'.:

object $date1, a date/time object for the 'from' date.:

object $date2, a date/time object for the 'to' date.:

string $format:

object $node, the node this date comes from (may be incomplete, always contains nid).:

object $view, the view this node comes from, if applicable.:

Return value

formatted date.

1 theme call to theme_date_all_day()
date_formatter_process in date/date.module
Helper function for creating formatted date arrays from a formatter.

File

date/date.theme, line 321
Theme functions.

Code

function theme_date_all_day($field, $which, $date1, $date2, $format, $node, $view = NULL) {
  if (empty($date1) || !is_object($date1) || $format == 'format_interval') {
    return '';
  }
  if (empty($date2)) {
    $date2 = $date1;
  }
  $granularity = array_pop(date_format_order($format));
  if (empty($field['granularity'])) {
    $field['granularity'] = date_format_order($format);
  }
  $increment = $field['widget']['increment'];
  $max_seconds = array_pop(date_seconds('s', TRUE, $increment));
  $max_minutes = array_pop(date_minutes('i', TRUE, $increment));
  switch ($granularity) {
    case 'second':
      $min_comp = date_format($date1, 'H:i:s') == '00:00:00';
      $max_comp = date_format($date2, 'H:i:s') == '00:00:00' || date_format($date2, 'H:i:s') == '23:' . $max_minutes . ':' . $max_seconds;
      break;
    case 'minute':
      $min_comp = date_format($date1, 'H:i') == '00:00';
      $max_comp = date_format($date2, 'H:i:s') == '00:00:00' || date_format($date2, 'H:i') == '23:' . $max_minutes;
      break;
    case 'hour':
      $min_comp = date_format($date1, 'H') == '00';
      $max_comp = date_format($date2, 'H:i:s') == '00:00:00' || date_format($date2, 'H') == '23';
      break;
    default:
      $min_comp = TRUE;
      $max_comp = FALSE;
  }

  // Time runs from midnight to the maximum time -- call it 'All day'.
  if (date_has_time($field['granularity']) && $min_comp && $max_comp) {
    $format = date_limit_format($format, array(
      'year',
      'month',
      'day',
    ));
    return trim(date_format_date(${$which}, 'custom', $format) . ' ' . theme('date_all_day_label'));
  }
  elseif (!date_has_time($field['granularity'])) {
    $format = date_limit_format($format, array(
      'year',
      'month',
      'day',
    ));
    return date_format_date(${$which}, 'custom', $format);
  }
  else {
    return date_format_date(${$which}, 'custom', $format);
  }
}