You are here

function date_popup_process_time in Date 6.2

Same name and namespace in other branches
  1. 5.2 date_popup/date_popup.module \date_popup_process_time()
  2. 6 date_popup/date_popup.module \date_popup_process_time()
  3. 7 date_popup/date_popup.module \date_popup_process_time()

Process the time portion of the element.

1 call to date_popup_process_time()
date_popup_process in date_popup/date_popup.module
Javascript popup element processing. Add popup attributes to $element.

File

date_popup/date_popup.module, line 349
A module to enable jquery calendar and time entry popups. Requires the Date API.

Code

function date_popup_process_time(&$element, $edit = NULL, $date = NULL) {
  $granularity = $element['#granularity'];
  $time_granularity = array_intersect($granularity, array(
    'hour',
    'minute',
    'second',
  ));
  $time_format = date_popup_format_to_popup_time(date_limit_format($element['#date_format'], $time_granularity));
  if (empty($time_granularity)) {
    return array();
  }
  $spinner_text = array(
    t('Now'),
    t('Previous field'),
    t('Next field'),
    t('Increment'),
    t('Decrement'),
  );
  $settings = array(
    'show24Hours' => strpos($element['#date_format'], 'H') !== FALSE ? TRUE : FALSE,
    'showSeconds' => in_array('second', $granularity) ? TRUE : FALSE,
    'timeSteps' => array(
      1,
      intval($element['#date_increment']),
      in_array('second', $granularity) ? $element['#date_increment'] : 0,
    ),
    'spinnerImage' => '',
    'fromTo' => isset($fromto),
  );

  // Create a unique id for each set of custom settings.
  $id = date_popup_js_settings_id($element['#id'], 'timeEntry', $settings);

  // Manually build this element and set the value - this will prevent corrupting
  // the parent value
  $parents = array_merge($element['#parents'], array(
    'time',
  ));
  $sub_element = array(
    '#type' => 'textfield',
    '#default_value' => (!empty($element['#value']) || !empty($edit['time'])) && is_object($date) ? date_format_date($date, 'custom', $time_format) : '',
    '#id' => $id,
    '#input' => FALSE,
    '#size' => 10,
    '#maxlength' => 10,
    '#parents' => $parents,
    '#name' => array_shift($parents) . '[' . implode('][', $parents) . ']',
  );
  $sub_element['#value'] = $sub_element['#default_value'];

  // TODO, figure out exactly when we want this description. In many places it is not desired.
  $sub_element['#description'] = t('Format: @date', array(
    '@date' => date_format_date(date_now(), 'custom', $time_format),
  ));
  return $sub_element;
}