You are here

function date_local_date in Date 7.3

Same name and namespace in other branches
  1. 8 date_elements.inc \date_local_date()
  2. 5.2 date/date_elements.inc \date_local_date()
  3. 6.2 date/date_elements.inc \date_local_date()
  4. 6 date/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 152
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?
  // @codingStandardsIgnoreStart

  /*
  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_DATETIME, $db_timezone);
  }
  */

  // @codingStandardsIgnoreEnd
  $date = new DateObject($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;
}