You are here

function date_local_date in Date 8

Same name and namespace in other branches
  1. 5.2 date/date_elements.inc \date_local_date()
  2. 6.2 date/date_elements.inc \date_local_date()
  3. 6 date/date_elements.inc \date_local_date()
  4. 7.3 date_elements.inc \date_local_date()
  5. 7 date_elements.inc \date_local_date()
  6. 7.2 date_elements.inc \date_local_date()

Create local date object.

Create a date object set to local time from the field and widget settings and item values. Default values for new entities are set by the default value callback, so don't need to be accounted for here.

1 call to date_local_date()
date_combo_element_process in ./date_elements.inc
Process an individual date element.

File

./date_elements.inc, line 20
Date forms and form themes and validation.

Code

function date_local_date($item, $timezone, $field, $instance, $part = 'value') {
  $value = $item[$part];

  // If the value is empty, don't try to create a date object because it will
  // end up being the current day.
  if (empty($value)) {
    return NULL;
  }

  // @TODO Figure out how to replace date_fuzzy_datetime() function.
  // Special case for ISO dates to create a valid date object for formatting.
  // Is this still needed?

  /*
  if ($field['type'] == DATE_ISO) {
    $value = date_fuzzy_datetime($value);
  }
  else {
    $db_timezone = date_get_timezone_db($field['settings']['tz_handling']);
    $value = date_convert($value, $field['type'], DATE_ISO, $db_timezone);
  }
  */
  $date = new DrupalDateTime($value, date_get_timezone_db($field['settings']['tz_handling']));
  if (empty($date)) {
    return NULL;
  }
  date_timezone_set($date, timezone_open($timezone));
  return $date;
}