4

I'm trying to troubleshoot and solve this problem: the server I'm working on (php 5.2.9 on Linux), has the correct local time (America/Buenos_Aires):

user@server [/home/site/public_html]$ date
Mon Nov  1 17:11:14 ART 2010

php.ini is set with date.timezone = "America/Buenos_Aires" I also tried to set the timezone directly in the script with

<?php
ini_set('display_errors', true);
error_reporting(E_ALL|E_STRICT|E_NOTICE);

//date_default_timezone_set("America/Buenos_Aires"); 
//echo  date_default_timezone_get(), "<br>";
echo "ini: ", ini_get('date.timezone'), "<br>";

$now = date("H:i:s T I");
$nowdate = date("Y-m-d");
echo $nowdate." ".$now;
?>

but to no avail, the result is

ini: America/Buenos_Aires
2010-11-01 18:11:14 ARST 1

when it should read 17:11 (It's consistently one hour ahead). All I've found here and on the web pointed to

  • date_default_timezone_set (which I tried)
  • setting date.timezone in php.ini (which it is set)
  • confusing server time with client time (which I'm not).

Any ideas?

EDIT: As suggested, I checked and as you can see in the code, PHP thinks it should be applying DST, and Argentina decided to not apply it this year. Any option besides waiting for a patch?

EDIT 2: I tried dumping the timezones transition as suggested. I got the following:

The timezone America/Buenos_Aires switches to standard time on 20 Mar 2011 @ 02:00.
The new GMT offset will be: -10800 (ART) 
Adriano Varoli Piazza
  • 7,297
  • 5
  • 39
  • 50

1 Answers1

10

There was a question a few days back that suggested that PHP hasn't yet got wind of the fact that Argentina got rid of DST only this year. It seems like this decision hasn't made it into the code base yet. (But it was not confirmed, so it's not 100% clear whether this was it.)

Maybe try dumping your time zones the same way to see whether that applies to your PHP version, too.

Update: This indeed seems to be the problem. The best solution I can think of is to use an offset in the time zone, e.g. Etc/GMT-3

Somebody should file a bug with bugs.php.net, there doesn't seem to be one for this.

Community
  • 1
  • 1
Pekka
  • 442,112
  • 142
  • 972
  • 1,088
  • I seemed to remember the same thing happening a few years ago... That might be it. Thanks! – Adriano Varoli Piazza Nov 01 '10 at 20:25
  • 1
    This is espacially visible in the original question, as the wrong time is in "ARST" but the correct time is in "ART". – Emil Vikström Nov 01 '10 at 20:27
  • @Adriano good question! One thing would be to file a bug with bugs.php.net so it gets cleaned up - there doesn't seem to be a bug report yet. As to what to do, does `date_default_timezone_set()` accept a pure offset? Maybe you can force a `-0300` (or whatever's correct right now, I'm confused :) on it for the time being. – Pekka Nov 01 '10 at 20:37
  • @Adriano it doesn't accept offsets, but try `Etc/GMT-3` (see http://www.php.net/manual/en/timezones.others.php) – Pekka Nov 01 '10 at 20:38
  • @Pekka Oh, yes, I can also use a different timezone, but I'd like to know if there's a cleaner solution. – Adriano Varoli Piazza Nov 01 '10 at 20:39
  • @Adriano this looks like broken info. Apart from recompiling PHP with the correct timezone info, I don't think there is a way to fix it right now. – Pekka Nov 01 '10 at 20:39
  • `Etc/GMT-3` gives me 23:40:13 instead of 17:40. `Etc/GMT+3` did the trick, though. – Adriano Varoli Piazza Nov 01 '10 at 20:40
  • @Adriano strange, `ART` is officially `UTC-3`. Try `GMT+3` maybe it counts the wrong way? Edit: Ah, okay! – Pekka Nov 01 '10 at 20:43
  • 1
    I also filed the bug in bugs.php.net, thanks for the suggestion. I have to say, having filled everything here made for an easy bug report. – Adriano Varoli Piazza Nov 01 '10 at 20:47
  • 2
    You can just update the timezone database with "pecl install timezonedb". – Artefacto Nov 01 '10 at 23:53
  • @Adriano `@`-ing you to make you aware of @Artefacto's comment - good to know! – Pekka Nov 01 '10 at 23:54