Jump to content

Western Australia, daylight savings and PHP


peregrine

Recommended Posts

Hi folks, searched for an answer (both here and on the web at large) and came up with nothing.

 

Running PHP 5.1.6 on Fedora Core 6. PHP's reported timezone does not match up with the system's.

 

Western Australia had a trial of daylight savings time abruptly introduced from December 2006 to March 2007 (and again for the following two summers). Fedora has updated to correctly handle this change, but it seems PHP has not.

 

Example:

php > echo date("e",time());

Australia/Perth

php > echo date("r",time());

Tue, 27 Feb 2007 09:44:27 +0800

...

bash-3.1$ date -R

Tue, 27 Feb 2007 10:44:44 +0900

 

(+0800 is standard time, +0900 is daylight savings time. Switching the system date until after DST ends makes these two match up again, at +0800.)

 

Everything I've found suggests that PHP just reads a system timezone file somewhere, but it's clearly not the same one Fedora is using. (/etc/localtime and /usr/share/zoneinfo/Australia/Perth are correct and up to date.) How can I make PHP keep up with this timezone change?

Link to comment
Share on other sites

It would be sloppy, but you could add an if clause...

 

Yes I could, and yes it would. ;) I'd rather leave it as-is and show "+0800"; having it in local time is just a convenience for users in the particular case I'm working on.

 

But I'd much rather find out how to make PHP use up-to-date timezone data automagically. Can anyone help? (When I said that I'd found claims that PHP reads a system file, what I'd been looking at was a lot of discussion about North American timezone changes. So I'm sure there must be someone who's experienced this same problem, in another time and on another continent...)

Link to comment
Share on other sites

You could use strace to see what files php opens.

 

Thank you, this was very helpful.

 

Among the output, I find this:

open("/etc/localtime", O_RDONLY)        = 3

 

So it does appear to be reading from /etc/localtime (which oddly is not a link to anything). But /etc/localtime does have the up-to-date daylight savings information:

bash-3.1$ zdump -v /etc/localtime | grep "2006\|2007"
/etc/localtime  Sat Dec  2 17:59:59 2006 UTC = Sun Dec  3 01:59:59 2006 WST isdst=0 gmtoff=28800
/etc/localtime  Sat Dec  2 18:00:00 2006 UTC = Sun Dec  3 03:00:00 2006 WST isdst=1 gmtoff=32400
/etc/localtime  Sat Mar 24 17:59:59 2007 UTC = Sun Mar 25 02:59:59 2007 WST isdst=1 gmtoff=32400
/etc/localtime  Sat Mar 24 18:00:00 2007 UTC = Sun Mar 25 02:00:00 2007 WST isdst=0 gmtoff=28800
/etc/localtime  Sat Oct 27 17:59:59 2007 UTC = Sun Oct 28 01:59:59 2007 WST isdst=0 gmtoff=28800
/etc/localtime  Sat Oct 27 18:00:00 2007 UTC = Sun Oct 28 03:00:00 2007 WST isdst=1 gmtoff=32400

 

I am utterly confused now. Help?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.