1 date.elements.inc date_local_date($item, $timezone, $field, $instance, $part = 'value')

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.

File

core/modules/date/date.elements.inc, line 833
Date forms and form themes and validation.

Code

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

  $value = (!empty($item[$part])) ? $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;
  }

  $date = new BackdropDateTime($value, date_get_timezone_db($field['settings']['tz_handling']));
  $date->limitGranularity($field['settings']['granularity']);
  if (empty($date)) {
    return NULL;
  }
  date_timezone_set($date, timezone_open($timezone));

  return $date;
}