You are here

function date_entity_metadata_struct_setter in Date 7.3

Same name and namespace in other branches
  1. 7.2 date.module \date_entity_metadata_struct_setter()

Callback for setting an individual field value if a to-date may be there too.

Based on entity_property_verbatim_set().

The passed in unix timestamp (UTC) is converted to the right value and format dependent on the field.

$name is either 'value' or 'value2'.

1 call to date_entity_metadata_struct_setter()
date_entity_metadata_field_setter in ./date.module
Callback for setting field property values.
1 string reference to 'date_entity_metadata_struct_setter'
date_entity_metadata_property_info_alter in ./date.module
Callback to alter the property info of date fields.

File

./date.module, line 755

Code

function date_entity_metadata_struct_setter(&$item, $name, $value, $langcode, $type, $info) {
  if (!isset($value)) {
    $item[$name] = NULL;
  }
  else {
    $field = field_info_field($info['field_name']);
    $format = date_type_format($field['type']);
    $timezone_db = date_get_timezone_db($field['settings']['tz_handling']);
    $date = new DateObject($value, 'UTC');
    if ($timezone_db != 'UTC') {
      date_timezone_set($date, timezone_open($timezone_db));
    }
    $item[$name] = $date
      ->format($format);
  }
}