Commit 842d2d88 authored by RoshniPatel.addweb's avatar RoshniPatel.addweb Committed by johnv

Issue #2808909 by Roshni Patel, tejal.patel: Format dates with periods (a.m. and p.m.)

parent 92a4e60c
......@@ -113,9 +113,26 @@ function _office_hours_select_process($element, &$form_state, $form) {
'#default_value' => $element['#value']['minute'],
);
if ($element['#field_settings']['hoursformat'] == 1) {
// ampm options, taken from date_ampm().
$options = date_ampm();
$element['ampm'] = array(
'#type' => 'select',
'#options' => date_ampm(),
'#options' => $options,
'#default_value' => $element['#value']['ampm'],
);
}
elseif ($element['#field_settings']['hoursformat'] == 3) {
// ampm options, taken from date_ampm().
$none = array('' => '');
$ampm = array(
'am' => t('a.m.', array(), array('context' => 'ampm')),
'pm' => t('p.m.', array(), array('context' => 'ampm')),
);
$options = $none + $ampm;
$element['ampm'] = array(
'#type' => 'select',
'#options' => $options,
'#default_value' => $element['#value']['ampm'],
);
}
......@@ -130,11 +147,11 @@ function _office_hours_select_validate($element, &$form_state) {
$hours = $element['hours']['#value'];
$minutes = ($element['minutes']['#value'] == 0) ? '00' : $element['minutes']['#value'];
if ($element['#field_settings']['hoursformat'] == 1) {
// 12 hrs format.
if ($element['ampm']['#value'] == 'pm' && $hours < 1200) {
// 12 hrs format with 'a.m.' or 'am'.
if ($element['ampm']['#value'][0] == 'p' && $hours < 1200) {
$hours += 1200;
}
if ($element['ampm']['#value'] == 'am' && $hours == 1200) {
if ($element['ampm']['#value'][0] == 'a' && $hours == 1200) {
$hours = '0000';
}
}
......
......@@ -142,6 +142,7 @@ function office_hours_field_settings_form($field, $instance, $has_data) {
2 => t('24 hrs') . ' (09:00)',
0 => t('24 hrs') . ' (9:00)',
1 => t('12 hrs') . ' (9:00 am)',
3 => t('12 hrs') . ' (9:00 a.m.)',
),
'#default_value' => $settings['hoursformat'],
'#required' => FALSE,
......
......@@ -100,6 +100,7 @@ function office_hours_field_formatter_settings_form($field, $instance, $view_mod
2 => t('24 hrs') . ' (09:00)',
0 => t('24 hrs') . ' (9:00)',
1 => t('12 hrs') . ' (9:00 am)',
3 => t('12 hrs') . ' (9:00 a.m.)',
),
'#default_value' => $settings['hoursformat'],
'#required' => FALSE,
......
......@@ -28,6 +28,11 @@ function theme_office_hours_field_formatter_default($vars) {
// 12hr ampm without leading zero.
$timeformat = 'g:i a';
break;
case 3:
// 12hr format as a.m. - p.m. without leading zero.
$timeformat = 'g:i a';
break;
}
// Minimum width for day labels. Adjusted when adding new labels.
......@@ -59,6 +64,9 @@ function theme_office_hours_field_formatter_default($vars) {
);
}
$times = implode($settings['separator_more_hours'], $times);
if ($settings['hoursformat'] == 3) {
$times = str_replace(array('am','pm'), array('a.m.','p.m.'), $times);
}
}
$info['output_label'] = $label;
......
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