Moodle

Timezone Problem

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Critical Critical
  • Resolution: Fixed
  • Affects Version/s: 1.9
  • Fix Version/s: 1.8.5, 1.9.1
  • Component/s: General
  • Labels:
    None
  • Environment:
    Linux
  • Database:
    MySQL
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_18_STABLE, MOODLE_19_STABLE

Description

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.

Issue Links

Activity

Hide
Mathieu Petit-Clair added a comment -

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...

Show
Mathieu Petit-Clair added a comment - 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...
Hide
Danya massadeh added a comment -

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.

Show
Danya massadeh added a comment - 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.
Hide
Mathieu Petit-Clair added a comment -

I commited a fix sent by Eloy.

Show
Mathieu Petit-Clair added a comment - I commited a fix sent by Eloy.
Hide
Eloy Lafuente (stronk7) added a comment -

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

Show
Eloy Lafuente (stronk7) added a comment - 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
Hide
Mathieu Petit-Clair added a comment -

Danya, can you confirm that this is fixed for you?

Show
Mathieu Petit-Clair added a comment - Danya, can you confirm that this is fixed for you?
Hide
Danya massadeh added a comment -

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.

Show
Danya massadeh added a comment - 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.
Hide
Danya massadeh added a comment -

BTW .. I just updated the timezone profile from admin front end.

Show
Danya massadeh added a comment - BTW .. I just updated the timezone profile from admin front end.
Hide
Eloy Lafuente (stronk7) added a comment -

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?

Show
Eloy Lafuente (stronk7) added a comment - 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?
Hide
Eloy Lafuente (stronk7) added a comment - - 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

Show
Eloy Lafuente (stronk7) added a comment - - 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
Hide
Danya massadeh added a comment -

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?

Show
Danya massadeh added a comment - 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?
Hide
Eloy Lafuente (stronk7) added a comment - - 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

Show
Eloy Lafuente (stronk7) added a comment - - 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
Hide
Danya massadeh added a comment -

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.

Show
Danya massadeh added a comment - 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.
Hide
Eloy Lafuente (stronk7) added a comment -

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

Show
Eloy Lafuente (stronk7) added a comment - 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
Hide
Danya massadeh added a comment -

Hi ..

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

Thanx a lot for clarification.

Show
Danya massadeh added a comment - Hi .. oh .. sorry .. I understand your example in pre-comment in a wrong way. Thanx a lot for clarification.
Hide
Eloy Lafuente (stronk7) added a comment -

Hi,

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

Ciao

Show
Eloy Lafuente (stronk7) added a comment - Hi, great, it's really not easy to explain nor to understand... thanks! Ciao

People

Dates

  • Created:
    Updated:
    Resolved: