Issue Details (XML | Word | Printable)

Key: CONTRIB-1152
Type: Improvement Improvement
Status: Open Open
Priority: Major Major
Assignee: Mike Worth
Reporter: David Davies
Votes: 1
Watchers: 0
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Non-core contributed modules

MRBS prior to version 1.4.x mishandles timezones in some environments when displaying bookings made before change to daylight saving time when in daylight saving time. These booking times show as an hour early.

Created: 05/Apr/09 02:11 AM   Updated: 02/Dec/09 08:08 PM
Component/s: Block: Mrbs
Affects Version/s: 2.0
Fix Version/s: None

File Attachments: 1. Text File CONTRIB-1152.patch (8 kB)
2. Text File CONTRIB-1152_1.patch (9 kB)
3. Text File CONTRIB-1152_2.patch (46 kB)

Environment: PHP5 & MySQL running on Linux servers.
Issue Links:
Dependency
 

Database: MySQL
Participants: Anthony Borrow, David Davies, Mark Johnson and Mike Worth
Security Level: None
Difficulty: Easy
Affected Branches: MOODLE_20_STABLE


 Description  « Hide
Any bookings made prior to change to DST will have to be fixed using SQL. In tests, the following code (taken from version 1.4.1) fixes the problem for future time changes:

in web/config.inc.php the following needs to be added:

      • snip --*

// The timezone your meeting rooms run in. It is especially important
// to set this if you're using PHP 5 on Linux. In this configuration
// if you don't, meetings in a different DST than you are currently
// in are offset by the DST offset incorrectly.
//
$timezone = "Europe/London";

      • snip --*

If your server timezone is not that above, you will need to edit that line. q.v. http://uk3.php.net/timezones for those available.

in web/functions.inc the following needs to be added near the top of the file:

      • snip --*

/////////////////////////////////////////
// Set timezone, if one has been provided

global $timezone;

if (isset($timezone))
{
if (function_exists("date_default_timezone_set"))
{
date_default_timezone_set($timezone);
}
else
{
putenv("TZ=$timezone");
}
}

      • snip --*

I've tested the above by changing server dates on an Ubuntu server and making bookings before and after this year's DST period and everything behaves properly now.



 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
David Davies added a comment - 05/Apr/09 02:19 AM
Sorry, the meetings show up an hour late when moving from GMT to BST not an hour early as I stated in the summary. It's been a long week

Anthony Borrow added a comment - 05/Apr/09 02:46 AM
David - Thanks for reporting this, especially after a busy week. I appreciate you taking the time to do so. The suggested patch above looks like it is for the MRBS code rather than the new Moodle block version. Have you tested the change above in /blocks/mrbs/web/functions.php? The date_default_timezone_set function does not exist in the MRBS Moodle block. Also, specifying a particular timezone in config.php is not going to work. I think I need to work on fixing this in a more Moodle-esque way but to do so, I need to be able to re-create the problem on my end so that I can see what is happening, where and why. Any help folks can give me to better understand the root of this issue would be helpful. I do not think creating a global variable and using the code above is a good idea. In fact, that is part of why I forked as I thought the MRBS code was becoming sloppy. Peace - Anthony

Anthony Borrow added a comment - 05/Apr/09 02:57 AM
I sent the MRBS project email a message to see how we might resolve some of our concerns. In all honesty, I would be happy to pass off maintenance of the MRBS Moodle block project to someone else if they are interested. I would still provide all the help I can; however, I do not feel I have the time to give this block the TLC that it needs to keep it functional for the Moodle community. Peace - Anthony

David Davies added a comment - 05/Apr/09 05:15 AM
Anthony - Afraid we're not using Moodle. I was just giving back to your community in exchange for the SQL fix which got us out of a hole on Monday morning. I would expect the function to work, but you will have to feed it the timezone from somewhere. Some sort of configuration issue I guess. in Xp. David

David Davies added a comment - 05/Apr/09 05:19 AM
Anthony - date_default_timezone_set is a php function btw qv http://uk3.php.net/date_default_timezone_set - David

Anthony Borrow added a comment - 05/Apr/09 05:24 AM
No worries David - thanks for taking the time to create the issue. I'll wait for the folks who are using Moodle to give me more information. I have some ideas I just want to make sure I understand the situation completely before I start making changes. All of the timezone stuff is pretty complicated and makes me dizzy and it is handled mostly by other functions in Moodle in the block so I'll wait and see what we figure out. Peace - Anthony

Anthony Borrow added a comment - 05/Apr/09 05:46 AM
David - Thanks for the link about the date_default_timezone_set function. It is a PHP 5 function so now I understand why they were checking for it. I'll have to give it some thought since Moodle 1.9 does not require PHP 5. Peace - Anthony

David Davies added a comment - 07/Apr/09 05:32 PM
Those running MRBS in PHP 5 on Linux would be the ones with the problem Anthony. PHP 4 is no longer supported, so I would expect most to be running PHP 5 by now, but not necessarily on a Linux server. in Xp. David

Mark Johnson added a comment - 05/Oct/09 04:22 PM
I just ran into this problem using Moodle's MRBS block - I'm working on a patch now.

Mark Johnson added a comment - 05/Oct/09 05:50 PM
This patch creates the function mrbs_correct_dst which works out if the time passed to it is in DST when the current time is not (or vice versa) and corrects it as appropriate.
If a booking that takes place after the switch to DST is being made before the switch, the time is altered so that is will be correct after the switch.
If a booking that takes place after the switch to DST is being viewed before the switch, the time is altered so that it looks correct before the switch.
The calls to the function are in edit_entry_handler.php, day.php, week.php and userweek.php. Let me know if I've missed anywhere.

Anthony Borrow added a comment - 05/Oct/09 10:56 PM - edited
Mike - I am going to go ahead an re-assign this to you for the time being. Might you have a moment to review/test this patch. I took a quick look and it looks good to me but I did not actually test it. If it tests out OK, let's go ahead and apply this. Thanks for your help. Peace - Anthony

p.s. - If you do not have time, then just re-assign the issue back to me and I'll get to it when I can.


Mark Johnson added a comment - 06/Oct/09 03:59 PM
It turns out that patch doesn't fix userweek.php. I'll take another look later today.

Mark Johnson added a comment - 06/Oct/09 07:11 PM
That first patch only applies the fix to the day view. This applies it to day, week, month and userweek, so ignore the first one.

Mark Johnson added a comment - 27/Oct/09 12:01 AM - edited
This patch works in addition to the previous one to allow bookings made before a switch to or from DST (using the method implemented in the previous patch) to show up alongside "normal" bookings after a switch to/from DST occurs.
Your PHP setup must be configured with the correct timezone on your server, or the changes will not be recognised correctly - don't leave it set to UTC!