You are here

function date_select_input_date in Date 7.3

Same name and namespace in other branches
  1. 7 date_api/date_api_elements.inc \date_select_input_date()
  2. 7.2 date_api/date_api_elements.inc \date_select_input_date()

Helper function for creating a date object out of user input.

3 calls to date_select_input_date()
date_select_element_process in date_api/date_api_elements.inc
Flexible date/time drop-down selector.
date_select_element_value_callback in date_api/date_api_elements.inc
Element value callback for date_select element.
date_select_validate in date_api/date_api_elements.inc
Validation function for date selector.
1 string reference to 'date_select_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 776
Date API elements themes and validation.

Code

function date_select_input_date($element, $input) {

  // Was anything entered? If not, we have no date.
  if (!is_array($input)) {
    return NULL;
  }
  else {
    $entered = array_values(array_filter($input));
    if (empty($entered)) {
      return NULL;
    }
  }
  $granularity = date_format_order($element['#date_format']);
  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']);

  // Make the input match the granularity.
  foreach (date_nongranularity($granularity) as $part) {
    unset($input[$part]);
  }
  $date = new DateObject($input, $element['#date_timezone']);
  if (is_object($date)) {
    $date
      ->limitGranularity($granularity);
    if ($date
      ->validGranularity($granularity, $element['#date_flexible'])) {
      date_increment_round($date, $element['#date_increment']);
    }
    return $date;
  }
  return NULL;
}