function date_local_date in Date 7
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()
- 6 date/date_elements.inc \date_local_date()
- 7.3 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_field_widget_form in ./
date_elements.inc - Private implementation of hook_widget().
File
- ./
date_elements.inc, line 121 - Date forms and form themes and validation.
Code
function date_local_date($form, $form_state, $delta, $item, $timezone, $field, $instance, $part = 'value') {
if (!empty($form['nid']['#value'])) {
$default_value = '';
$default_value_code = '';
}
elseif ($part == 'value') {
$default_value = $instance['settings']['default_value'];
$default_value_code = $instance['settings']['default_value_code'];
}
else {
$default_value = $instance['settings']['default_value2'];
$default_value_code = $instance['settings']['default_value_code2'];
}
if (empty($item) || empty($item[$part])) {
if (empty($default_value) || $default_value == 'blank' || $delta > 0) {
return NULL;
}
elseif ($part == 'value2' && $default_value == 'same') {
if ($instance['settings']['default_value'] == 'blank' || empty($item['value'])) {
return NULL;
}
else {
$date = new DateObject($item['value'], $timezone, DATE_FORMAT_DATETIME);
$date
->limitGranularity($field['settings']['granularity']);
}
}
elseif ($field['settings']['tz_handling'] == 'none') {
$date = date_now();
}
else {
$date = date_now($timezone);
}
}
else {
$value = $item[$part];
// @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?
/*
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);
}
*/
$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));
}
if (is_object($date) && empty($item[$part]) && $default_value == 'strtotime' && !empty($default_value_code)) {
date_modify($date, $default_value_code);
}
return $date;
}