You are here

function date_popup_input_date in Date 7.2

Same name and namespace in other branches
  1. 7.3 date_popup/date_popup.module \date_popup_input_date()
  2. 7 date_popup/date_popup.module \date_popup_input_date()

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.

2 calls to date_popup_input_date()
date_popup_element_value_callback in date_popup/date_popup.module
Element value callback for date_popup 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_date'
date_input_date in ./date.module
Wrapper function around each of the widget types for creating a date object.

File

date_popup/date_popup.module, line 649
A module to enable jQuery calendar and time entry popups.

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']) && empty($input['time'])) {
    return NULL;
  }
  date_popup_add();
  $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) : '';

  // Check if date is empty, if yes, then leave it blank.
  $datetime = !empty($input['date']) ? trim($input['date']) : '';
  $datetime .= $has_time ? ' ' . trim($input['time']) : '';
  $date = new DateObject($datetime, $element['#date_timezone'], $format);

  // If the variable is time only then set TimeOnly to TRUE.
  if (empty($input['date']) && !empty($input['time'])) {
    $date->timeOnly = 'TRUE';
  }
  if (is_object($date)) {
    $date
      ->limitGranularity($granularity);
    if ($date
      ->validGranularity($granularity, $flexible)) {
      date_increment_round($date, $element['#date_increment']);
    }
    return $date;
  }
  return NULL;
}