Commit e9b6395e authored by tim.plunkett's avatar tim.plunkett Committed by tim.plunkett

Issue #1273946 by Dmitriy.trt, tim.plunkett | ralf.strobel: Added Option to...

Issue #1273946 by Dmitriy.trt, tim.plunkett | ralf.strobel: Added Option to override user time zone in date handlers.
parent dfe10cee
......@@ -26,6 +26,7 @@ function option_definition() {
$options['date_format'] = array('default' => 'small');
$options['custom_date_format'] = array('default' => '');
$options['timezone'] = array('default' => '');
return $options;
}
......@@ -65,6 +66,18 @@ function options_form(&$form, &$form_state) {
':input[name="options[date_format]"]' => array('value' => $custom_date_possible),
);
}
$form['timezone'] = array(
'#type' => 'select',
'#title' => t('Timezone'),
'#description' => t('Timezone to be used for date output.'),
'#options' => array('' => t('- Default site/user timezone -')) + system_time_zones(FALSE),
'#default_value' => $this->options['timezone'],
);
foreach (array_merge(array('custom'), array_keys($date_formats)) as $timezone_date_formats) {
$form['timezone']['#states']['visible'][] = array(
':input[name="options[date_format]"]' => array('value' => $timezone_date_formats),
);
}
parent::options_form($form, $form_state);
}
......@@ -77,6 +90,7 @@ function render($values) {
}
if ($value) {
$timezone = !empty($this->options['timezone']) ? $this->options['timezone'] : NULL;
$time_diff = REQUEST_TIME - $value; // will be positive for a datetime in the past (ago), and negative for a datetime in the future (hence)
switch ($format) {
case 'raw time ago':
......@@ -95,11 +109,11 @@ function render($values) {
return t(($time_diff < 0 ? '%time hence' : '%time ago'), array('%time' => format_interval(abs($time_diff), is_numeric($custom_format) ? $custom_format : 2)));
case 'custom':
if ($custom_format == 'r') {
return format_date($value, $format, $custom_format, null, 'en');
return format_date($value, $format, $custom_format, $timezone, 'en');
}
return format_date($value, $format, $custom_format);
return format_date($value, $format, $custom_format, $timezone);
default:
return format_date($value, $format);
return format_date($value, $format, '', $timezone);
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment