MDL-9729 Ensure start of week day calculation observes user timezone setting in the same way as month start and end dates. Prevents incorrect display of dates (1 out) on main Moodle calendar display although mini calendar display is correct. (Merged from 1.8 stable branch)

This commit is contained in:
dwoolhead 2007-05-29 09:56:44 +00:00
parent bc1637c730
commit 6cc1a80532

View file

@ -328,18 +328,19 @@ function calendar_show_month_detailed($m, $y, $courses, $groups, $users) {
list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display list($d, $m, $y) = array($date['mday'], $date['mon'], $date['year']); // This is what we want to display
$display->maxdays = calendar_days_in_month($m, $y); $display->maxdays = calendar_days_in_month($m, $y);
$startwday = 0;
if (get_user_timezone_offset() < 99) { if (get_user_timezone_offset() < 99) {
// We 'll keep these values as GMT here, and offset them when the time comes to query the db // We 'll keep these values as GMT here, and offset them when the time comes to query the db
$display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT $display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
$display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT $display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT
$startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
} else { } else {
// no timezone info specified // no timezone info specified
$display->tstart = mktime(0, 0, 0, $m, 1, $y); $display->tstart = mktime(0, 0, 0, $m, 1, $y);
$display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); $display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y);
$startwday = date('w', $display->tstart); // $display->tstart not necessarily GMT, so use date()
} }
$startwday = gmdate('w', $display->tstart); // $display->tstart is already GMT, so don't use date(): messes with server's TZ
// Align the starting weekday to fall in our display range // Align the starting weekday to fall in our display range
if($startwday < $display->minwday) { if($startwday < $display->minwday) {
$startwday += 7; $startwday += 7;