Addressing bug 1257:

Changed the handling of time display format; now it's read from the language
file by default, and a new preference has been added to allow each user to
manually specify his preferred time format.
This commit is contained in:
defacer 2004-04-22 09:02:23 +00:00
parent c867774d76
commit 1b0ebe79b1
4 changed files with 59 additions and 1 deletions

View file

@ -50,6 +50,8 @@ define ('SECS_IN_DAY', 86400);
define ('CALENDAR_UPCOMING_DAYS', 14);
define ('CALENDAR_UPCOMING_MAXEVENTS', 10);
define ('CALENDAR_URL', $CFG->wwwroot.'/calendar/');
define ('CALENDAR_TF_24', '%H:%M');
define ('CALENDAR_TF_12', '%I:%M %p');
function calendar_get_mini($courses, $groups, $users, $cal_month = false, $cal_year = false) {
global $CFG, $USER;
@ -674,7 +676,13 @@ function calendar_day_representation($tstamp, $now = false, $usecommonwords = tr
}
function calendar_time_representation($time) {
return userdate($time, '%H:%M');
static $langtimeformat = NULL;
if($langtimeformat === NULL) {
$langtimeformat = get_string('strftimetime');
}
$timeformat = get_user_preferences('calendar_timeformat');
// The ? is needed because the preference might be present, but empty
return userdate($time, empty($timeformat) ? $langtimeformat : $timeformat);
}
function calendar_get_link_href($linkbase, $d, $m, $y) {
@ -1160,6 +1168,7 @@ function calendar_preferences_array() {
'startwday' => get_string('pref_startwday', 'calendar'),
'maxevents' => get_string('pref_maxevents', 'calendar'),
'lookahead' => get_string('pref_lookahead', 'calendar'),
'timeformat' => get_string('pref_timeformat', 'calendar'),
);
}

View file

@ -66,6 +66,18 @@
if($_GET['commit']) {
switch($_GET['edit']) {
case 'timeformat':
if($_GET['timeformat'] == '12') {
$timeformat = CALENDAR_TF_12;
}
else if($_GET['timeformat'] == '24') {
$timeformat = CALENDAR_TF_24;
}
else {
$timeformat = '';
}
set_user_preference('calendar_'.$_GET['edit'], $timeformat);
break;
case 'startwday':
$day = intval($_GET[$_GET['edit']]);
if($day < 0 || $day > 6) {
@ -192,6 +204,24 @@
}
switch($_GET['edit']) {
case 'timeformat':
$sel = array('default' => ' selected="selected"', '12' => '', '24' => '');
switch(get_user_preferences('calendar_timeformat', '')) {
case CALENDAR_TF_12:
$sel['12'] = $sel['default'];
$sel['default'] = '';
break;
case CALENDAR_TF_24:
$sel['24'] = $sel['default'];
$sel['default'] = '';
break;
}
echo '<td><select name="timeformat">';
echo '<option value="default"'.$sel['default'].'>'.get_string('default', 'calendar').'</option>';
echo '<option value="12"'.$sel['12'].'>'.get_string('timeformat_12', 'calendar').'</option>';
echo '<option value="24"'.$sel['24'].'>'.get_string('timeformat_24', 'calendar').'</option>';
echo '</select></td>';
break;
case 'startwday':
echo '<td>';
$days = array(
@ -227,6 +257,17 @@
get_string('thursday', 'calendar'), get_string('friday', 'calendar'),
get_string('saturday', 'calendar'));
$values['startwday'] = $days[$values['startwday']];
switch($values['timeformat']) {
case '':
$values['timeformat'] = get_string('default', 'calendar');
break;
case CALENDAR_TF_12:
$values['timeformat'] = get_string('timeformat_12', 'calendar');
break;
case CALENDAR_TF_24:
$values['timeformat'] = get_string('timeformat_24', 'calendar');
break;
}
// OK, display them
foreach($prefs as $name => $description) {