date_popup_process_time_part
Drupal 7 date_popup_process_time_part(&$element)
Process the time portion of the element.
1 call to date_popup_process_time_part()
File
- sites/
all/ modules/ date/ date_popup/ date_popup.module, line 364 - A module to enable jquery calendar and time entry popups. Requires the Date API.
Code
function date_popup_process_time_part(&$element) {
$granularity = date_format_order($element['#date_format']);
$has_time = date_has_time($granularity);
if (empty($has_time)) {
return array();
}
switch ($element['#timepicker']) {
case 'default':
$func = 'timeEntry';
$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),
);
if (strpos($element['#date_format'], 'a') !== FALSE) {
// Then we are using lowercase am/pm.
$settings['ampmNames'] = array('am', 'pm');
}
if (strpos($element['#date_format'], ' A') !== FALSE || strpos($element['#date_format'], ' a') !== FALSE) {
$settings['ampmPrefix'] = ' ';
}
break;
case 'wvega':
$func = 'timepicker';
$time_granularity = array_intersect($granularity, array('hour', 'minute', 'second'));
$format = date_popup_format_to_popup_time(date_limit_format($element['#date_format'], $time_granularity), 'wvega');
// The first value in the dropdown list should be the same as the element
// default_value, but it needs to be in JS format (i.e. milliseconds since
// the epoch).
$start_time = new DateObject($element['#default_value'], $element['#date_timezone'], DATE_FORMAT_DATETIME);
date_increment_round($start_time, $element['#date_increment']);
$start_time = $start_time->format(DATE_FORMAT_UNIX) * 1000;
$settings = array(
'timeFormat' => $format,
'interval' => $element['#date_increment'],
'startTime' => $start_time,
'scrollbar' => TRUE,
);
break;
default:
$func = '';
$settings = array();
break;
}
// Create a unique id for each set of custom settings.
$id = date_popup_js_settings_id($element['#id'], $func, $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',
'#title' => $element['#date_label_position'] == 'above' ? theme('date_part_label_time', array('part_type' => 'time', 'element' => $element)) : '',
'#default_value' => $element['#value']['time'],
'#id' => $id,
'#size' => 15,
'#maxlength' => 10,
'#attributes' => $element['#attributes'],
'#parents' => $parents,
'#name' => array_shift($parents) . '[' . implode('][', $parents) . ']',
'#ajax' => !empty($element['#ajax']) ? $element['#ajax'] : FALSE,
);
$sub_element['#value'] = $sub_element['#default_value'];
// TODO, figure out exactly when we want this description. In many places it is not desired.
$example_date = date_now();
date_increment_round($example_date, $element['#date_increment']);
$sub_element['#description'] = t('E.g., @date', array('@date' => date_format_date($example_date, 'custom', date_popup_time_format($element))));
return ($sub_element);
}

