Issue Details (XML | Word | Printable)

Key: MDL-13959
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Critical Critical
Assignee: Mathieu Petit-Clair
Reporter: Danya massadeh
Votes: 0
Watchers: 1
Operations

Add/Edit UI Mockup to this issue
If you were logged in you would be able to see more operations.
Moodle

Timezone Problem

Created: 18/Mar/08 08:32 PM   Updated: 25/Apr/08 03:35 AM
Return to search
Component/s: General
Affects Version/s: 1.9
Fix Version/s: 1.8.5, 1.9.1

Environment: Linux
Issue Links:
Relates

Database: MySQL
Participants: Danya massadeh, Eloy Lafuente (stronk7) and Mathieu Petit-Clair
Security Level: None
QA Assignee: Eloy Lafuente (stronk7)
Resolved date: 20/Mar/08
Affected Branches: MOODLE_19_STABLE
Fixed Branches: MOODLE_18_STABLE, MOODLE_19_STABLE


 Description  « Hide
The timezone in all North America states are wrong in 1 hour difference, I update the timezones using http://download.moodle.org/timezone/ but the last year is 2007.

when I test it using $userDate = usergetdate(mktime(),'America/Adak'); for example .. it is different than the time in http://www.timeanddate.com/worldclock/city.html?n=13

It is so imortanat .. I developed many tasks depends on this time ... plz fix it as soon as possible.

Thanx alot.

 All   Comments   Change History   Version Control      Sort Order: Ascending order - Click to sort in descending order
Mathieu Petit-Clair added a comment - 19/Mar/08 02:53 PM
Eloy had a look at this and it appears that usergetdate() is using the current logged-in user ($USER) timezone (or the site timezone, I suppose) to make the calculations. He sent me a patch that mostly fixes this issue, but I still have a problem with it. More news as soon as possible...

Danya massadeh added a comment - 19/Mar/08 07:46 PM
yes .. usergetdate() is using the current logged-in user ($USER) timezone, but I use the same function and pass diferent parameter,
even so ... if I change the timezone from "edit profile" and logout then login .. there is 1 hour difference in north America stats and canada.

Mathieu Petit-Clair added a comment - 20/Mar/08 12:09 PM
I commited a fix sent by Eloy.

Eloy Lafuente (stronk7) added a comment - 23/Mar/08 09:34 AM
I also have update timezone info to latest package available (2008a - MDL-14024). It seems to have only changes related to Argentina and Chile.

Ciao


Mathieu Petit-Clair added a comment - 08/Apr/08 01:49 PM
Danya, can you confirm that this is fixed for you?

Danya massadeh added a comment - 11/Apr/08 01:11 AM
I still have complaints from my users ... for example ... "America/New_York" .. is says that there is 5 hours difference "gmtoff = -300" for 2007 .. and it should be 4 hours. is that right?

Thanx alot.


Danya massadeh added a comment - 11/Apr/08 01:16 AM
BTW .. I just updated the timezone profile from admin front end.

Eloy Lafuente (stronk7) added a comment - 11/Apr/08 08:21 AM
Hi Danya:

New York standard time (gmtoff) is -5 hours (300). And there is one DST (dstoff) in action since March 9th, of +1 hour (60). And that's exactly what the timezones information says.

Also, I've tried the usergetdate() function, asking for America/New_York times and results obtained from Moodle are exactly the same than the ones at: http://www.timeanddate.com/worldclock/city.html?n=179

So... what are you getting? Correct or incorrect results?


Eloy Lafuente (stronk7) added a comment - 11/Apr/08 08:23 AM - edited
Also... note that it isn't a matter of updating the timezones from admin. Also you need to update your Moodle to the latest 1.8.5+ or 1.9+ release to get the usergetdate() (and other) functions working properly. Have you?

Ciao


Danya massadeh added a comment - 11/Apr/08 08:58 PM
Thanx alot Eloy for your quick response ...

I just installed 1.9+ (I didn't before) and checked the function .. when I tried this:

$mktime = mktime(14, 0, 0, 4 ,09, 2008);
$userDate = usergetdate($mktime,'America/New_York');
$mktime2 = mktime($userDate['hours'], $userDate['minutes'], 0, $userDate['mon'] , $userDate['mday'], $userDate['year']);
$sessionTm2 = date('g:i a.',$mktime2);
print $sessionTm2;

I get 9:00 AM .. but as the site (http://www.timeanddate.com/worldclock/city.html?n=179) .. it should be 10:00AM (14 = 2:00PM GMT)

Is that right?


Eloy Lafuente (stronk7) added a comment - 11/Apr/08 10:38 PM - edited
Ah, no! That's pretty incorrect (in order to correctly handle timezones and DSTs!)

You need to use Moodle functions to guarantee that everything is ok, without mixing php functions (mktime, date...) with moodle functions (usergetdate).

So, to get the GMT timestamp of one date... you need to execute:

$timestamp = make_timestamp(2008, 4, 9, 14, 0, 0, 'America/New_York');

And then you can handle that GMT timestamp as you prefer, for example:

  • To print the date of that GMT timestamp in different cities (timezones):
    echo userdate($timestamp, '', 'America/New_York');
    echo userdate($timestamp, '', 'Spanin/Madrid');
  • To get the date components of that GMT timestamp in different cities (timezones):
    print_object( usergetdate($timestamp, 'America/New_York'));
    print_object( usergetdate($timestamp, 'Europe/Madrid'));

But, as you see, ALWAYS using Moodle functions that will handle both the timezone and the dst properly.

Note also, that if you doesn't use the timezone parameter in the functions above... then the user timezone will be used automatically (normal Moodle behaviour).

Ciao


Danya massadeh added a comment - 15/Apr/08 08:38 PM
Thanks alot Eloy .. and sorry to be late ..

as you said .. I installed the new time functions in (moodlelib.php) .. I can't replace all files because the semester not finished yet.
so yep .. it is working fine , but one thing I want to mention plz:

for this code:

$timestamp = make_timestamp(2008, 4, 9, 14, 0, 0, 'America/New_York');
echo userdate($timestamp, '', 'America/New_York');

the result will be:
Wednesday, 9 April 2008, 02:00 PM ... which is wrong.

but if you write:

$timestamp = make_timestamp(2008, 4, 9, 14, 0, 0); // WITHOUT TIMEZONE
echo userdate($timestamp, '', 'America/New_York');

the result will be:
Wednesday, 9 April 2008, 10:00 AM ... which is right.

Really thanx alot Eloy.


Eloy Lafuente (stronk7) added a comment - 16/Apr/08 02:17 AM
Hi Danya,

I really don't understand why you say that this is wrong:

$timestamp = make_timestamp(2008, 4, 9, 14, 0, 0, 'America/New_York');
echo userdate($timestamp, '', 'America/New_York');

the result will be:
Wednesday, 9 April 2008, 02:00 PM ... which is wrong.

It's perfect IMO. If you request one timestamp for NY and then print it (also for NY) time must be EXACTLY the original one. It's a trivial case.

Problem arrive when you MIX functions using and not using the timezone explicitly, because then, your server timezone is used by default. So, your second example is really dependent of your server timezone, because you request one timestamp using your server timezone (4 hours before NY) and then want to print what time is in NY (4 hours after you).

I really don't understand why you say the 1st example is wrong, one NY timestamp will show one NY userdate, so they MUST be equal (in fact something would be really wrong if that caused different times to be shown).

Ciao


Danya massadeh added a comment - 25/Apr/08 02:48 AM
Hi ..

oh .. sorry .. I understand your example in pre-comment in a wrong way.

Thanx a lot for clarification.


Eloy Lafuente (stronk7) added a comment - 25/Apr/08 03:35 AM
Hi,

great, it's really not easy to explain nor to understand... thanks!

Ciao