Lebowtech Blog

Update PHP Time Zone for DST in Israel 5774

| Comments

So for what ever reason the Israeli government decided to change the law and extend Day Light Savings Time, שעון קיץ this year. The should just get rid of DST in my opinion, and I would be willing to bet that many people share that opinion.

Any way this change in DST means that may scripts are making wrong time calculations.

To fix this in PHP, you can use Athens for the time zone in Israel, but that is really hackish. The real fix is to install the new PECL timezone database.

First thing you need to do if you are running Mac OS X is to install PECL and Pear. Jason McCreany provides detailed instructions.

Next you just need to install the pear package, timezonedb.

1
sudo pecl install timezonedb

Then add the following line to your php.ini file, most likely /etc/php.ini.

1
extension=timezonedb.so

Test it in php like this

1
2
3
4
5
6
7
8
9
 print_r(new DateTime);
/*
DateTime Object
(
    [date] => 2013-10-10 12:15:14
    [timezone_type] => 3 // this means we are at GMT+3 and still in DST, summer time
    [timezone] => Asia/Jerusalem
)
*/

You can restart Apache now to see your changes reflected on your php scripts running over the web.

Comments