You are here

function date_entity_metadata_struct_getter in Date 7.2

Same name and namespace in other branches
  1. 7.3 date.module \date_entity_metadata_struct_getter()
  2. 7 date.module \date_entity_metadata_struct_getter()

Getter callback to return date values as datestamp in UTC.

2 calls to date_entity_metadata_struct_getter()
date_entity_metadata_duration_getter in ./date.module
Getter callback to return the duration of the time period given by the dates.
date_entity_metadata_field_getter in ./date.module
Getter callback to return date values as datestamp in UTC from the field.
1 string reference to 'date_entity_metadata_struct_getter'
date_entity_metadata_property_info_alter in ./date.module
Callback to alter the property info of date fields.

File

./date.module, line 663

Code

function date_entity_metadata_struct_getter($item, array $options, $name, $type, $info) {

  // Return early if we don't have a value to work with.
  if (!isset($item[$name])) {
    return NULL;
  }
  $value = trim($item[$name]);
  if (empty($value)) {
    return NULL;
  }

  // Determine timezone data from the field if available.
  if (isset($info['field']['settings']['tz_handling'])) {
    $timezone_db = date_get_timezone_db($info['field']['settings']['tz_handling']);
  }
  elseif (!empty($item['timezone_db'])) {
    $timezone_db = $item['timezone_db'];
  }
  else {
    $timezone_db = 'UTC';
  }
  $date = new DateObject($value, $timezone_db);
  return !empty($date) ? date_format_date($date, 'custom', 'U') : NULL;
}