You are here

function date_selector_make_dbdate in Date 5

Construct a value to save to the database from the date selector

Parameters

$array - an array of date parts collected by the date selector: @param $type - DATE_UNIX or DATE_ISO @param $timezone_in - timezone of supplied value @param $granularity = an array of date parts to be selected, like array('Y','M','D'), default is M, D, Y Y => year, M => month, D => day, H => hours, N => minutes, S => seconds, T => timezone

2 calls to date_selector_make_dbdate()
date_selector_validate in ./date.inc
Validation function for date selector $params = an array of values including: required = is a valid date required, default is true opt_fields = an array of fields that need not be filled out, default is empty array
date_widget in ./date.module
Implementation of hook_widget().

File

./date.inc, line 985
Date/time API functions

Code

function date_selector_make_dbdate($array, $type = DATE_ISO, $timezone_in = 'GMT', $granularity = array(
  'M',
  'D',
  'Y',
)) {

  // adjust back to 24 hours time if 12 hours input was collected
  if ($array['ampm'] == 'pm' && $array['hours'] < 12) {
    $array['hours'] += 12;
  }

  // try to construct a date from the submitted values
  $date = date_make_date();
  if ($type == DATE_UNIX) {
    if (date_set_date($date, date_array2unix($array), $timezone_in, 'local', $type)) {
      return $date;
    }
  }
  elseif ($type == DATE_ISO) {
    if (date_set_date($date, date_array2iso($array), $timezone_in, 'local', $type)) {
      return $date;
    }
  }
  return FALSE;
}