You are here

function bat_form_values_get_start_end_dates in Booking and Availability Management Tools for Drupal 7

Given a form state array, locate the start/end dates in the values array and instantiate and return DateTime objects.

File

./bat.module, line 631
Provides basic underlying functionality and configuration options used by all BAT modules.

Code

function bat_form_values_get_start_end_dates($form_state) {

  // Date values have a format of year-month-day.
  // This is one of the default expected formats, so there
  // is no need to explicitly define the format.
  // (see http://www.php.net/manual/en/datetime.formats.date.php)
  $start_date = $form_state['values']['bat_start_date'];
  $end_date = $form_state['values']['bat_end_date'];

  // If the input format is numeric we assume that is a Unix timestamp.
  if (is_numeric($start_date) && is_numeric($end_date)) {

    // The @ lets the DateTime class know that the date is
    // formatted as a Unix timestamp.
    $start_date = '@' . $start_date;
    $end_date = '@' . $end_date;
  }
  $start = new DateTime($start_date);
  $end = new DateTime($end_date);
  return array(
    $start,
    $end,
  );
}