Working for DST support.
This commit is contained in:
+11
-14
@@ -152,7 +152,7 @@
|
||||
}
|
||||
else {
|
||||
$other = get_record('dst_preset', 'name', $preset->name);
|
||||
if($preset->id != $other->id) {
|
||||
if($other !== false && $preset->id != $other->id) {
|
||||
$errors[] = get_string('errordstpresetnameexists', 'admin');
|
||||
}
|
||||
}
|
||||
@@ -163,18 +163,15 @@
|
||||
// Are we error-free?
|
||||
if(empty($errors)) {
|
||||
// Calculate the last/next/current_offset variables
|
||||
// WARNING: TODO: BUG: To calculate the timestamps, we are taking into account
|
||||
// the admin's own DST setting. That means that if the admin changes his own DST
|
||||
// setting and with this change his effective DST status changes, the timestamps
|
||||
// will NOT be calculated correctly. Thus, the whole DST setting will be wrong
|
||||
// for ALL USERS!
|
||||
$preset->activate_time = sprintf('%02d:%02d', $preset->activate_hour, $preset->activate_minute);
|
||||
$preset->deactivate_time = sprintf('%02d:%02d', $preset->deactivate_hour, $preset->deactivate_minute);
|
||||
$preset = calendar_dst_update_preset($preset);
|
||||
print_object("record is:");
|
||||
print_object($preset);
|
||||
print_object('The last change time (DST) was: '.strftime('%A, %d %B %Y %H:%M', $preset->last_change));
|
||||
print_object('The last change time (user) was: '.userdate($preset->last_change));
|
||||
print_object('The next change time (DST) is : '.strftime('%A, %d %B %Y %H:%M', $preset->next_change));
|
||||
print_object('The next change time (user) is : '.userdate($preset->next_change));
|
||||
print_object('The last change time was: ');
|
||||
print_object(gmdate('M d Y H:i', $preset->last_change));
|
||||
print_object('The next change time is: ');
|
||||
print_object(gmdate('M d Y H:i', $preset->next_change));
|
||||
|
||||
// Write it!
|
||||
if($preset->id) {
|
||||
@@ -189,14 +186,14 @@
|
||||
die();
|
||||
}
|
||||
else {
|
||||
print_simple_box_start('center', '70%', '#cc0000');
|
||||
echo '<div style="color: #fff;"><div style="font-weight: bold; text-align: center;">'.get_string('therewereerrors', 'admin').':</div>';
|
||||
echo '<div class="errorbox">';
|
||||
echo '<h1>'.get_string('therewereerrors', 'admin').':</h1>';
|
||||
echo '<ul>';
|
||||
foreach($errors as $error) {
|
||||
echo '<li>'.$error.'</li>';
|
||||
}
|
||||
echo '</ul></div>';
|
||||
print_simple_box_end();
|
||||
echo '</ul>';
|
||||
echo '</div>';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -25,7 +25,7 @@
|
||||
<?php choose_from_menu(array('1' => get_string('first', 'calendar'), '-1' => get_string('last', 'calendar')), 'activate_index', $preset->activate_index, ''); ?>
|
||||
<?php choose_from_menu($weekdays, 'activate_day', $preset->activate_day, ''); ?>
|
||||
<?php print_string('dstof', 'calendar'); echo ' '; calendar_print_month_selector('activate_month', $preset->activate_month); ?>
|
||||
<?php print_string('dstat', 'calendar'); echo ' '; print_time_selector('activate_hour', 'activate_minute', make_timestamp(2000, 1, 1, $preset->activate_hour, $preset->activate_minute), 30); ?>
|
||||
<?php print_string('dstat', 'calendar'); echo ' '; print_time_selector('activate_hour', 'activate_minute', make_timestamp(2000, 1, 1, $preset->activate_hour, $preset->activate_minute), 99, false); ?>
|
||||
<?php $preset->activate_hour; ?>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -50,7 +50,7 @@
|
||||
<?php choose_from_menu(array('1' => get_string('first', 'calendar'), '-1' => get_string('last', 'calendar')), 'deactivate_index', $preset->deactivate_index, ''); ?>
|
||||
<?php choose_from_menu($weekdays, 'deactivate_day', $preset->deactivate_day, ''); ?>
|
||||
<?php print_string('dstof', 'calendar'); echo ' '; calendar_print_month_selector('deactivate_month', $preset->deactivate_month); ?>
|
||||
<?php print_string('dstat', 'calendar'); echo ' '; print_time_selector('deactivate_hour', 'deactivate_minute', make_timestamp(2000, 1, 1, $preset->deactivate_hour, $preset->deactivate_minute), 30); ?>
|
||||
<?php print_string('dstat', 'calendar'); echo ' '; print_time_selector('deactivate_hour', 'deactivate_minute', make_timestamp(2000, 1, 1, $preset->deactivate_hour, $preset->deactivate_minute), 99, false); ?>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
+15
-2
@@ -1304,11 +1304,24 @@ function calendar_dst_update_preset($dstpreset) {
|
||||
}
|
||||
|
||||
function calendar_dst_changes_for_year($year, $dstpreset) {
|
||||
|
||||
$monthdayactivate = calendar_find_day_in_month($dstpreset->activate_index, $dstpreset->activate_day, $dstpreset->activate_month, $year);
|
||||
$monthdaydeactivate = calendar_find_day_in_month($dstpreset->deactivate_index, $dstpreset->deactivate_day, $dstpreset->deactivate_month, $year);
|
||||
|
||||
list($activate_hour, $activate_minute) = explode(':', $dstpreset->activate_time);
|
||||
list($deactivate_hour, $deactivate_minute) = explode(':', $dstpreset->deactivate_time);
|
||||
if(isset($dstpreset->activate_time)) {
|
||||
list($activate_hour, $activate_minute) = explode(':', $dstpreset->activate_time);
|
||||
}
|
||||
else {
|
||||
$activate_hour = $dstpreset->activate_hour;
|
||||
$activate_minute = $dstpreset->activate_minute;
|
||||
}
|
||||
if(isset($dstpreset->deactivate_time)) {
|
||||
list($deactivate_hour, $deactivate_minute) = explode(':', $dstpreset->deactivate_time);
|
||||
}
|
||||
else {
|
||||
$deactivate_hour = $dstpreset->deactivate_hour;
|
||||
$deactivate_minute = $dstpreset->deactivate_minute;
|
||||
}
|
||||
|
||||
$timezone = get_user_timezone(99);
|
||||
$timeactivate = make_timestamp($year, $dstpreset->activate_month, $monthdayactivate, $activate_hour, $activate_minute, 0, $timezone, false);
|
||||
|
||||
+16
-37
@@ -592,51 +592,30 @@ function make_timestamp($year, $month=1, $day=1, $hour=0, $minute=0, $second=0,
|
||||
$time = mktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year, 0);
|
||||
} else {
|
||||
$time = gmmktime((int)$hour,(int)$minute,(int)$second,(int)$month,(int)$day,(int)$year, 0);
|
||||
$time = usertime($time, $timezone); // This is GMT
|
||||
$time = usertime($time, $timezone);
|
||||
}
|
||||
|
||||
if(!$applydst) {
|
||||
return $time;
|
||||
}
|
||||
|
||||
return $time;
|
||||
|
||||
/*
|
||||
// WARNING: BUG: TODO: This is buggy, but it will do for testing purposes
|
||||
if(($dstid = get_user_preferences('calendar_dstpreset')) !== NULL) {
|
||||
$preset = get_record('dst_preset', 'id', $dstid);
|
||||
if($time > $preset->last_change && $time < $preset->next_change) {
|
||||
|
||||
if($time >= $preset->last_change && $time < $preset->next_change) {
|
||||
$time -= $preset->current_offset * 60;
|
||||
return $time;
|
||||
}
|
||||
|
||||
// We need to find out what's going on...
|
||||
$nowuserdate = usergetdate($time);
|
||||
|
||||
// It's in some other time period, we need to recalculate
|
||||
$changes = calendar_dst_changes_for_year($year, $preset);
|
||||
if($time < $changes['activate'] || $time > $changes['deactivate']) {
|
||||
// DST will be off at that time
|
||||
if($preset->current_offset != 0) {
|
||||
print_object('Uncompensated time was:');
|
||||
print_object(usergetdate($time));
|
||||
$time += $preset->apply_offset * 60;
|
||||
print_object('Compensated time is:');
|
||||
print_object(usergetdate($time));
|
||||
}
|
||||
|
||||
if($time >= $changes['activate'] && $time < $changes['deactivate']) {
|
||||
// Compensation required
|
||||
$time -= $preset->apply_offset * $preset->apply_offset_sign;
|
||||
}
|
||||
else {
|
||||
// DST will be on at that time
|
||||
if($preset->current_offset == 0) {
|
||||
print_object('Uncompensated time was:');
|
||||
print_object(usergetdate($time));
|
||||
$time -= $preset->apply_offset * 60;
|
||||
print_object('Compensated time is:');
|
||||
print_object(usergetdate($time));
|
||||
}
|
||||
}
|
||||
|
||||
return $time;
|
||||
}
|
||||
*/
|
||||
return $time;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -751,24 +730,24 @@ function userdate($date, $format='', $timezone=99, $fixday = true) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a $date timestamp in GMT (seconds since epoch),
|
||||
* Given a $time timestamp in GMT (seconds since epoch),
|
||||
* returns an array that represents the date in user time
|
||||
*
|
||||
* @uses HOURSECS
|
||||
* @param int $date Timestamp in GMT
|
||||
* @param int $time Timestamp in GMT
|
||||
* @param int $timezone ?
|
||||
* @return array An array that represents the date in user time
|
||||
* @todo Finish documenting this function
|
||||
*/
|
||||
function usergetdate($date, $timezone=99) {
|
||||
function usergetdate($time, $timezone=99) {
|
||||
|
||||
$timezone = get_user_timezone($timezone);
|
||||
|
||||
if (abs($timezone) > 13) {
|
||||
return getdate($date);
|
||||
return getdate($time);
|
||||
}
|
||||
//There is no gmgetdate so I have to fake it...
|
||||
$date = $date + (int)($timezone * HOURSECS);
|
||||
$time += (int)($timezone * HOURSECS);
|
||||
|
||||
// This is independent of the server's TZ settings,
|
||||
// unlike gmstrftime. It's also a bit faster this way.
|
||||
@@ -783,7 +762,7 @@ function usergetdate($date, $timezone=99) {
|
||||
$getdate['yday'],
|
||||
$getdate['weekday'],
|
||||
$getdate['month']
|
||||
) = explode(' ', gmdate('s i H d m Y w z l F', $date));
|
||||
) = explode(' ', gmdate('s i H d m Y w z l F', $time));
|
||||
|
||||
return $getdate;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user