function date_deploy_rebuild_date_datetime in Deploy - Content Staging 6
Rebuilds 'datetime' dates.
See also
1 call to date_deploy_rebuild_date_datetime()
- date_deploy_rebuild_date in modules/
date_deploy/ date_deploy.module - Proxy function for rebuilding a date field array. The array structure that we shall build varies based on widget type, also the date input varies based on date type.
File
- modules/
date_deploy/ date_deploy.module, line 51
Code
function date_deploy_rebuild_date_datetime($date, $field) {
$rebuild = array();
$timezone_db = new DateTimeZone($date['timezone_db']);
$timezone = new DateTimeZone($date['timezone']);
$format = isset($field['widget']['input_format_custom']) && $field['widget']['input_format_custom'] ? $field['widget']['input_format_custom'] : $field['widget']['input_format'];
// Some date fields have a to and from date, so we'll need to account for
// that.
$value['value'] = new DateTime($date['value'], $timezone_db);
$value['value']
->setTimezone($timezone);
if (isset($date['value2'])) {
$value['value2'] = new DateTime($date['value2'], $timezone_db);
$value['value2']
->setTimezone($timezone);
}
foreach ($value as $key => $datetime) {
switch ($field['widget']['type']) {
// date_popup requires both "date" and "time" data. Granularity has been
// taken into account in the format value available in the field
// definition.
case 'date_popup':
$rebuild[$key]['date'] = $datetime
->format(date_limit_format($format, array(
'year',
'month',
'day',
)));
$rebuild[$key]['time'] = $datetime
->format(date_limit_format($format, array(
'hour',
'minute',
'second',
)));
break;
// The date_select widget requires a breakdown of each element of the
// date. Granularity will be taken into account during validation, so we
// don't need to handle it here. For whatever reason "0" is not valid via
// FAPI for "minute", only "00".
case 'date_select':
// We don't use date_parse() here since that function isn't supported
// in all version with RHEL. See http://drupal.org/node/924454 .
$timestamp = $datetime
->format('U');
$parts['year'] = date('Y', $timestamp);
$parts['month'] = date('n', $timestamp);
$parts['day'] = date('j', $timestamp);
$parts['hour'] = date('G', $timestamp);
$parts['minute'] = date('i', $timestamp);
$parts['second'] = date('s', $timestamp);
$rebuild[$key] = array_intersect_key($parts, array_flip(array(
'year',
'month',
'day',
'hour',
'minute',
'second',
)));
break;
// Granularity has yet to be taken into account, so we'll have to handle
// it.
default:
$rebuild[$key]['date'] = $datetime
->format(date_limit_format($format, $field['granularity']));
break;
}
}
return $rebuild;
}