Did I miss something about the year?

Did I miss something about the year?

by Mark Burnet -
Number of replies: 8

Trying to figure why my calendar thinks it is Satuday the 7th and not Sunday the 7th. ? It looks more like a 2003 calendar on my system.

Attachment calshot.jpg
Average of ratings: -
In reply to Mark Burnet

Re: Did I miss something about the year?

by John Papaioannou -

Thank you for the report AND the screenshot. There still seems to be a problem... can you please post the timezones of:

  1. Your server
  2. Your Moodle configuration
  3. Your user account
In reply to John Papaioannou

Re: Did I miss something about the year?

by Mark Burnet -

Linux server date:

# date
Mon Mar  8 08:19:50 EST 2004
#

Moodle variable setting timezone= local server time

Admin user= local server time

In reply to John Papaioannou

Re: Did I miss something about the year?

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

Hi Jon -

The problem is indeed back. I have it as well again.

It looks like the culprit is in the 'calendar_get_mini' code. You compute the 'tstart' and 'tend' values of your calendar from the date at the user location using GMT. I don't think this is right.

If I change the two lines:

$display->tstart = gmmktime(0, 0, 0, $m, 1, $y); // This is GMT
$display->tend = gmmktime(23, 59, 59, $m, $display->maxdays, $y); // GMT

to:

$display->tstart = mktime(0, 0, 0, $m, 1, $y); // This is GMT
$display->tend = mktime(23, 59, 59, $m, $display->maxdays, $y); // GMT

it works.

I'm not sure if this will have other side effects though. The problem is that you calculate GMT based on $m and $y which are not GMT.

The same problem occurs with the 'calendar_show_month_detailed' function in the 'view.php' file.

mike

In reply to Mike Churchward

Re: Did I miss something about the year?

by Mark Burnet -
Mike, Did you check these changes into CVS or is Jon putting them in?
In reply to Mike Churchward

Re: Did I miss something about the year?

by John Papaioannou -
As I 've posted on the "even more cal development" thread:

I made a fix in CVS which (hopefully) solves this problem. Please get the latest files (for this fix, required are calendar/view.php and calendar/lib.php) and see if it now works for you.

I expect that this will fix all the problems that people with timezones negative to GMT had.

Mike, if it is what I think it is, the problem actually isn't in the lines you mention, even though the change you propose DOES fix it. I spent a lot of time a couple of days ago to convince myself that the code you quote is correct, and it is. Just find a GMT timestamp calclulator on the internet and check $display->tstart and $display->tend, they are correctly calclulated.

I believe the problem was in

$startwday = date('w', $display->tstart);

and more specifically:

$display->tstart is a GMT stamp. However, I think that date() compensates for the difference between localtime and GMT, thus reducing the tstart by a few hours and (since it was pointing at exactly midnight) bringing it into the previous day. So, the end result was that instead of finding what day of the week "March 1 2004, 00:00:00" was (Monday), it found out what day of the week "February 29 2004, 19:00:00" was (example for GMT-05) and thus broke the calendar display.

Please download the latest CVS code and see if this fixed the issue:

$startwday = gmdate('w', $display->tstart);

Regards,
Jon
In reply to John Papaioannou

Re: Did I miss something about the year?

by Mike Churchward -
Picture of Core developers Picture of Plugin developers Picture of Testers

I bow to your knowledge of your code. wink

That's why I didn't want to actually make the change. I was afraid it would have other nasty effects elsewhere. Your description of the fix makes sense, and when I tested it, it indeed worked.

Thanks!

mike