You are here

function datelist_get_input_date in Date 8

Helper function to turn the user input for a date list back into a qualified date object.

2 calls to datelist_get_input_date()
datelist_validate in date_api/date_api_elements.inc
Validates the date type to adjust 12 hour time and prevent invalid dates (e.g., February 30, 2006).
datelist_value_callback in date_api/date_api_elements.inc
Element value callback for datelist element.
1 string reference to 'datelist_get_input_date'
date_input_date in ./date.module
Wrapper function around each of the widget types for creating a date object.

File

date_api/date_api_elements.inc, line 404
Date API elements themes and validation. This file is only included during the edit process to reduce memory usage.

Code

function datelist_get_input_date($element, $input) {

  // Was anything entered? If not, we have no date.
  if (empty($input) || !is_array($input)) {
    return NULL;
  }
  $test_values = array_values(array_filter($input));
  if (empty($test_values)) {
    return NULL;
  }
  if (isset($input['ampm'])) {
    if ($input['ampm'] == 'pm' && $input['hour'] < 12) {
      $input['hour'] += 12;
    }
    elseif ($input['ampm'] == 'am' && $input['hour'] == 12) {
      $input['hour'] -= 12;
    }
    unset($input['ampm']);
  }
  return new \Drupal\Core\Datetime\DrupalDateTime($input);
}