diff --git a/etemplate/inc/class.date_widget.inc.php b/etemplate/inc/class.date_widget.inc.php index 801857dff6..96854e350a 100644 --- a/etemplate/inc/class.date_widget.inc.php +++ b/etemplate/inc/class.date_widget.inc.php @@ -105,7 +105,7 @@ 'm' => '', 'd' => '', 'H' => '', - 'i' => '' + 'i' => '', ); } elseif ($data_format != '') @@ -142,21 +142,17 @@ } $time_0h0 = !(int)$value['H'] && !(int)$value['i']; + $readonly = $cell['readonly'] || $readonlys; + $timeformat = array(3 => 'H', 4 => 'i'); - if ($this->timeformat == '12') + if ($this->timeformat == '12' && $readonly && $value['H'] !== '') { $value['a'] = $value['H'] < 12 ? 'am' : 'pm'; - - if ($value['H'] > 12) - { - $value['H'] -= 12; - } + $value['H'] = $value['H'] % 12 ? $value['H'] % 12 : 12; // no leading 0 and 0h => 12am $timeformat += array(5 => 'a'); } $format = split('[/.-]',$this->dateformat); - $readonly = $cell['readonly'] || $readonlys; - // no time also if $options&8 and readonly and time=0h0 if ($type != 'date' && !($readonly && ($options & 8) && $time_0h0)) { @@ -164,6 +160,8 @@ } if ($readonly) // is readonly { + if ($value['H'] === '') unset($value['a']); // no am/pm if no hour set + $sep = array( 1 => $this->dateformat[1], 2 => $this->dateformat[1], @@ -209,7 +207,7 @@ 'm' => 'select-month', 'M' => 'select-month', 'd' => 'select-day', - 'H' => 'select-number', + 'H' => 'select-hour', 'i' => 'select-number' ); $opts = array( @@ -282,19 +280,6 @@ unset($dcell); } if ($type == 'date-houronly') $n++; // no minutes - - if ($n == 4 && $type != 'date' && $this->timeformat == '12') - { - $dcell = $tpl->empty_cell(); - $dcell['type'] = 'radio'; - $dcell['name'] = 'a'; - $dcell['help'] = $cell['help']; - $dcell['size'] = $dcell['label'] = 'am'; - $row[$tpl->num2chrs(++$i)] = $dcell; - $dcell['size'] = $dcell['label'] = 'pm'; - $row[$tpl->num2chrs(++$i)] = &$dcell; - unset($dcell); - } } $tpl->data[0] = array(); $tpl->data[1] = &$row; @@ -525,13 +510,6 @@ $value['d'] = $value['m'] = 1; $value['Y'] = 1970; } - if (isset($value['a'])) - { - if ($value['a'] == 'pm' && $value['H'] < 12) - { - $value['H'] += 12; - } - } // checking the date is a correct one if (!checkdate($value['m'],$value['d'],$value['Y'])) { diff --git a/etemplate/inc/class.select_widget.inc.php b/etemplate/inc/class.select_widget.inc.php index 293e9c2e34..92373c3152 100644 --- a/etemplate/inc/class.select_widget.inc.php +++ b/etemplate/inc/class.select_widget.inc.php @@ -47,6 +47,7 @@ 'select-month' => 'Select Month', 'select-day' => 'Select Day', 'select-dow' => 'Select Day of week', + 'select-hour' => 'Select Hour', // either 0-23 or 0am-11am,12pm,1pm-11pm 'select-number' => 'Select Number', 'select-app' => 'Select Application' ); @@ -426,6 +427,16 @@ $cell['no_lang'] = True; break; + case 'select-hour': + for ($h = 0; $h <= 23; ++$h) + { + $cell['sel_options'][$h] = $GLOBALS['egw_info']['user']['preferences']['common']['timeformat'] == 12 ? + (($h % 12 ? $h % 12 : 12).' '.($h < 12 ? lang('am') : lang('pm'))) : + sprintf('%02d',$h); + } + $cell['no_lang'] = True; + break; + case 'select-app': // type2: ''=users enabled apps, 'installed', 'all' = not installed ones too $apps = array(); foreach ($GLOBALS['egw_info']['apps'] as $app => $data)