1 date.elements.inc date_popup_input_date($element, $input, $auto_complete = FALSE)

Helper function for extracting a date value out of user input.

Parameters

bool $auto_complete: Should we add a time value to complete the date if there is no time? Useful anytime the time value is optional.

File

core/modules/date/date.elements.inc, line 1277
Date forms and form themes and validation.

Code

function date_popup_input_date($element, $input, $auto_complete = FALSE) {
  if (empty($input) || !is_array($input) || !array_key_exists('date', $input) || empty($input['date'])) {
    return NULL;
  }
  $granularity = date_format_order($element['#date_format']);
  $has_time = date_has_time($granularity);
  $flexible = !empty($element['#date_flexible']) ? $element['#date_flexible'] : 0;

  $format = _date_popup_date_format($element);
  $format .= $has_time ? ' ' . _date_popup_time_format($element) : '';
  $datetime = trim($input['date']);
  $datetime .= $has_time ? ' ' . trim($input['time']) : '';
  $date = new BackdropDateTime($datetime, $element['#date_timezone'], $format);
  if (is_object($date)) {
    $date->limitGranularity($granularity);
    if ($date->validGranularity($granularity, $flexible)) {
      date_increment_round($date, $element['#date_increment']);
    }
    return $date;
  }
  return NULL;
}