function date_popup_input_value in Date 6.2
Same name and namespace in other branches
- 5.2 date_popup/date_popup.module \date_popup_input_value()
- 6 date_popup/date_popup.module \date_popup_input_value()
Helper function for extracting a date value out of user input.
Parameters
autocomplete: Should we add a time value to complete the date if there is no time? Useful anytime the time value is optional.
2 calls to date_popup_input_value()
- date_popup_process in date_popup/
date_popup.module - Javascript popup element processing. Add popup attributes to $element.
- date_popup_validate in date_popup/
date_popup.module - Massage the input values back into a single date.
1 string reference to 'date_popup_input_value'
- date_input_value in date/
date.module
File
- date_popup/
date_popup.module, line 454 - A module to enable jquery calendar and time entry popups. Requires the Date API.
Code
function date_popup_input_value($element, $auto_complete = FALSE) {
date_popup_load();
$granularity = date_format_order($element['#date_format']);
$format = $element['#date_format'];
$format = strtr($format, timepicker_format_replacements());
$format = date_limit_format($format, $granularity);
// Evaluate date and time parts separately since we can't know or care
// how they're combined in the complete date format.
$time_format = date_limit_format($format, array(
'hour',
'minute',
'second',
));
$date_format = date_limit_format($format, array(
'year',
'month',
'day',
));
$value = '';
if (is_array($element['#value']) && !empty($element['#value']['date'])) {
$date = date_convert_from_custom(trim(!empty($element['#value']['date']) ? $element['#value']['date'] : ''), $date_format);
$time = date_convert_from_custom(trim(!empty($element['#value']['time']) ? $element['#value']['time'] : ''), $time_format);
$value = trim(drupal_substr($date, 0, 10) . ' ' . drupal_substr($time, 11, 8));
}
if (date_is_valid($value, DATE_DATETIME, $granularity)) {
$date = date_make_date($value, $element['#date_timezone'], DATE_DATETIME, $granularity);
$value = date_convert($date, DATE_OBJECT, DATE_DATETIME);
return $value;
}
return NULL;
}