php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54481 date_default_timezone_get() returns incorrect timezone
Submitted: 2011-04-07 04:21 UTC Modified: 2011-04-08 12:12 UTC
From: stuart at horuskol dot net Assigned:
Status: Not a bug Package: Date/time related
PHP Version: Irrelevant OS: Linux/Ubuntu
Private report: No CVE-ID: None
 [2011-04-07 04:21 UTC] stuart at horuskol dot net
Description:
------------
We noticed a discrepancy between PHP and the server timezones, and found that one four different servers (with two different versions of PHP - 5.2.4 and 5.3.2) the server was set to Australia/Adelaide (ACST), but this date_default_timezone_get() was returning Asia/Jayapura (EIT).

There is no value in date.timezone (it is commented out) in the CLI and Apache PHP configuration files - so according to the documentation, PHP should be getting the timezone from the server configuration.

Why is it getting this random Asia/Jayapura value?

---
From manual page: http://www.php.net/function.date-default-timezone-get#Description
---

Test script:
---------------
echo date_default_timezone_get();

Expected result:
----------------
The correct timezone - not Asia/Jayapura when the server is set to Australia/Adelaide

Actual result:
--------------
Asia/Jayapura

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-08 11:39 UTC] derick@php.net
Automatic comment from SVN on behalf of derick
Revision: http://svn.php.net/viewvc/?view=revision&revision=310049
Log: - Clarify the guessing stage of date_default_timezone_get() a bit to prevent bug reports such as #54481.
 [2011-04-08 11:40 UTC] derick@php.net
-Status: Open +Status: Bogus
 [2011-04-08 11:40 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The guessing algorithm isn't perfect, that's why you *need* to make the date.timezone setting in php.ini. You will also get a warning when it's not set:

derick@whisky:~$ php -n -r 'echo date_default_timezone_get(), "\n";'

Warning: date_default_timezone_get(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/London' for 'BST/1.0/DST' instead in Command line code on line 1
Europe/London

So make sure you have display_errors on as well, as well as set error_reporting to include warnings. I've updated the documentation to reflect this.
 [2011-04-08 12:12 UTC] stuart at horuskol dot net
I don't quite see why this is not a bug...

Why, when I own my server(s) and want to be able to have a single point of configuration for timezones on that server (because of interoperating services like PHP and MySQL) instead of sharded configuration in separate files, can I not rely on my system timezone?

In addition - since the error is because I don't have default timezone set - something is going wrong with the request to the server for the timezone.

If you won't fix it, fair enough, but I don't think this is bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu May 02 17:01:31 2024 UTC