Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Fixed
-
Affects Version/s: 1.8.4, 1.9
-
Labels:None
-
Environment:Any, with timezones loaded...
-
Affected Branches:MOODLE_18_STABLE, MOODLE_19_STABLE
-
Fixed Branches:MOODLE_18_STABLE, MOODLE_19_STABLE
Description
Some days ago, with MDL-13959 , we fixed the usergetdate() to work properly with timezones passed as parameters, because DSTs weren't being properly calculated then. The solution was about to "save" the parameter value and then pass it straight to the dst_offset_on() function. Else, the original parameter became transformed and DST weren't applied.
The same behaviour can be extended to other moodlelib functions:
make_timestamp()
userdate()
usergetmidnight()
All them can accept one timezone parameter and, if used, DST aren't properly applied.
IMPORTANT NOTE: This doesn't affect normal Moodle operations, where the DST to be applied is calculated by looking server and user timezones. This ONLY affects it we want to know the time in another timezone (imagine one block showing different times or something like that).
So those functions should be patched with a similar solution that the one used for usergetdate() in MDL-13959.
Attaching one test to demonstrate how userdate() and usergetmidnight() fails when a custom timezone is passed. Results are this (with local clock set at 00:00:00):
Execution details:
Without tz, calculations are for timezone "Australia/Perth"
With tz, calculations are for timezone "Europe/Madrid"
Now: (1206745200)
Now (usergetdate-notz): 29-03-2008 08:00
Now (usergetdate-withtz): 29-03-2008 00:00
Now (userdate-notz): sábado, 29 de marzo de 2008, 08:00
Now (userdate-withtz): sábado, 29 de marzo de 2008, 01:00
Midnight (userdate-notz): sábado, 29 de marzo de 2008, 00:00 (mid: 1206716400)
Midnight (userdate-withtz): sábado, 29 de marzo de 2008, 00:00 (mid: 1206741600)
In 7 days (7*24*60*60 seconds): (1207350000)
7 (usergetdate-notz): 05-04-2008 07:00
7 (usergetdate-withtz): 05-04-2008 01:00
7 (userdate-notz): sábado, 5 de abril de 2008, 07:00
7 (userdate-withtz): sábado, 5 de abril de 2008, 00:00
Midnight (userdate-notz): sábado, 5 de abril de 2008, 00:00 (mid: 1207324800)
Midnight (userdate-withtz): sábado, 5 de abril de 2008, 00:00 (mid: 1207350000)