php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #44380 localtime sometimes gives GMT date, not local
Submitted: 2008-03-09 00:33 UTC Modified: 2008-03-28 01:00 UTC
Votes:2
Avg. Score:3.5 ± 0.5
Reproduced:2 of 2 (100.0%)
Same Version:1 (50.0%)
Same OS:1 (50.0%)
From: tessone at polyglut dot net Assigned: jani (profile)
Status: No Feedback Package: Date/time related
PHP Version: 5.2.5 OS: CentOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: tessone at polyglut dot net
New email:
PHP Version: OS:

 

 [2008-03-09 00:33 UTC] tessone at polyglut dot net
Description:
------------
When using localtime() to get the server time into an array, sometimes PHP chooses the local timezone, sometimes it chooses GMT.  I am in US/Eastern (-0500), so after 7pm, sometimes my script says it's today, sometimes tomorrow (because it is choosing GMT).

Below is some code, plus a result from when it chooses the local timezone (correct) and one where it chooses GMT (incorrect).

If I run date at the command-line, it consistently returns a US/Eastern time, so the server is not skipping back and forth between timezones for any reason.

Reproduce code:
---------------
print time() . ": ";

$serverTime = localtime(time());
print_r($serverTime);

print date("O");


Expected result:
----------------
1205022657: Array ( [0] => 57 [1] => 30 [2] => 19 [3] => 8 [4] => 2 [5] => 108 [6] => 6 [7] => 67 [8] => 0 ) -0500

Actual result:
--------------
1205022665: Array ( [0] => 5 [1] => 31 [2] => 0 [3] => 9 [4] => 2 [5] => 108 [6] => 0 [7] => 68 [8] => 0 ) +0000

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-03-13 12:08 UTC] jani@php.net
How/where do you set date.timezone ?
 [2008-03-13 18:53 UTC] tessone at polyglut dot net
As you can see from the sample code above, I haven't set date.timezone.  If I do set it, the erratic behavior stops.

However, it is a bug that without setting the timezone explicitly, the behavior is erratic and unpredictable.  It should default to either UTC or the system timezone, but it definitely should not alternate randomly between the two.
 [2008-03-14 12:11 UTC] jani@php.net
If you're using Apache, please check that there is no php_value/php_admin_value settings used in any vhost/directory (.htaccess/httpd.conf) to set the timezone.
 [2008-03-17 03:27 UTC] tessone at polyglut dot net
Nope, nothing like that in the main httpd.conf and no .htaccess files involved at all.
 [2008-03-17 20:51 UTC] jani@php.net
And main httpd.conf doesn't do any includes to add some extra conf parts..? (just to be sure here..you could try the latest snapshot JIC, some fixes were committed just last week)
 [2008-03-19 01:42 UTC] tessone at polyglut dot net
Nope, no includes.

I can't really run snapshots, though, as this is on a production server using CentOS packages.
 [2008-03-21 00:30 UTC] jani@php.net
No dev/test server to try with?
 [2008-03-28 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 16:01:27 2024 UTC