function date_local_date in Date 6
Same name and namespace in other branches
- 8 date_elements.inc \date_local_date()
- 5.2 date/date_elements.inc \date_local_date()
- 6.2 date/date_elements.inc \date_local_date()
- 7.3 date_elements.inc \date_local_date()
- 7 date_elements.inc \date_local_date()
- 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, using field settings to determine what to do with empty values.
1 call to date_local_date()
- _date_widget in date/
date_elements.inc - Private implementation of hook_widget().
File
- date/
date_elements.inc, line 181 - Date forms and form themes and validation.
Code
function date_local_date($delta, $item, $timezone, $field, $part = 'value') {
if ($part == 'value') {
$default_value = $field['widget']['default_value'];
$default_value_code = $field['widget']['default_value_code'];
}
else {
$default_value = $field['widget']['default_value2'];
$default_value_code = $field['widget']['default_value_code2'];
}
if (empty($item[$part])) {
if (empty($default_value) || $default_value == 'blank') {
return NULL;
}
elseif ($part == 'value2' && $default_value == 'same' && !empty($item['value'])) {
$date = date_make_date($item['value'], $timezone);
}
elseif ($field['tz_handling'] == 'none') {
$date = date_make_date('now', date_default_timezone_name());
}
else {
$date = date_make_date('now', $timezone);
}
}
else {
$value = $item[$part];
// Special case for ISO dates to create a valid date object for formatting.
if ($field['type'] == DATE_ISO) {
$value = date_fuzzy_datetime($value);
}
else {
$value = date_convert($value, $field['type'], DATE_DATETIME);
}
$date = date_make_date($value, 'UTC');
if (date_timezone_convert($field, $item)) {
date_timezone_set($date, timezone_open($timezone));
}
}
if (is_object($date) && empty($item[$part]) && $default_value == 'strtotime' && !empty($default_value_code)) {
date_modify($date, $default_value_code);
}
return $date;
}