You are here

function date_text_input_date in Date 7

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

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

2 calls to date_text_input_date()
date_text_element_value_callback in date_api/date_api_elements.inc
Element value callback for date_text element.
date_text_validate in date_api/date_api_elements.inc
Validation for text input.
1 string reference to 'date_text_input_date'
date_input_date in ./date.module

File

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

Code

function date_text_input_date($element, $input) {
  if (empty($input) || !is_array($input) || !array_key_exists('date', $input) || empty($input['date'])) {
    return NULL;
  }
  $granularity = date_format_order($element['#date_format']);
  $date = new DateObject($input['date'], $element['#date_timezone'], $element['#date_format']);
  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;
}