php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33545 Cannot find any timezone setting
Submitted: 2005-07-02 06:45 UTC Modified: 2005-07-03 13:31 UTC
From: xuefer at 21cn dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5CVS-2005-07-02 (dev) OS: cygwin
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: xuefer at 21cn dot com
New email:
PHP Version: OS:

 

 [2005-07-02 06:45 UTC] xuefer at 21cn dot com
Description:
------------
PHP 5.1.0-dev (cgi-fcgi) (built: Jun 28 2005 11:49:30) (DEBUG)

unset TZ && php.exe a.php
Content-type: text/html


Warning: date(): Cannot find any timezone setting in /usr/src/php5-debug/a.php on line 2
/usr/src/php5-debug/a.php(2) : Warning - date(): Cannot find any timezone setting

putenv("TZ"); before date() is ok however.
------

96      env = getenv("TZ");
97      if (env) {
98          return env;
99      }
(gdb) br 98
Breakpoint 1 at 0x42453b: file /usr/src/php5-src/ext/date/php_date.c, line 98.
(gdb) r
Breakpoint 1, guess_timezone ()
98          return env;
(gdb) p env
$1 = 0x100301a3 "   -8"

but i can't figure where env TZ is set, not my shell nor my script

Reproduce code:
---------------
<?php
echo date("Y:m:d");
?>


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-02 12:21 UTC] derick@php.net
Apparently the TV environment variable *is* set... you need to try to figure out where this happens. If it's not set by yourself, you should try to figure out why cygwin does this - that's obviously not PHP's problem.
 [2005-07-02 12:59 UTC] xuefer at 21cn dot com
$ export TZ=GMT
$ echo $TZ
GMT
$ gdb --args ./sapi/cgi/php.exe -b 1026
(gdb) br main
Breakpoint 1 at 0x71a0ab: file /home/Xuefer/src/php5/sapi/cgi/cgi_main.c, line 946.
(gdb) r
Starting program: /usr/src/php5-debug/sapi/cgi/php.exe -b 1026

Breakpoint 1, main (argc=3, argv=0x10031e60) at /home/Xuefer/src/php5/sapi/cgi/cgi_main.c:946
946 {
(gdb) p getenv("PATH")
$3 = 268634357
(gdb) p getenv("_")
$4 = 268637882
(gdb) p getenv("WINDIR")
$5 = 268632983
(gdb) p getenv("OS")
$6 = 268633155
no problem with other env, except TZ
(gdb) p getenv("TZ")
$1 = 0
(gdb) l php_module_startup
(gdb) br 1401
Breakpoint 2 at 0x653624: file /home/Xuefer/src/php5/main/main.c, line 1401.
(gdb) c
Continuing.

Breakpoint 2, php_module_startup (sf=0x7a81e0, additional_modules=0x0, num_additional_modules=0) at /home/Xuefer/src/php5/main/main.c:1401
1401        tzset();
(gdb) p getenv("TZ")
$3 = 0
(gdb) n
1412        le_index_ptr = zend_register_list_destructors_ex(NULL, NULL, "index pointer", 0);
(gdb) p (char*)getenv("TZ")
$5 = 0x100301a3 "   -8"
(gdb)

i'm not sure it's problem of cygwin or php of corse, as cygwin is not supported by php.
same problem in php4, but there's no warning with date() strtodate().
putenv("TZ=GMT"); helps, but not putenv("TZ"); in php script before date()

<?php
echo "<pre>";
echo "\nwith putenv TZ:";
putenv("TZ");
echo date("H");
echo "\nwith putenv TZ=GMT:";
putenv("TZ=GMT");
echo date("H");
echo "\nwith putenv TZ=GMT-8:";
putenv("TZ=GMT-8");
echo date("H");
echo "\nwith putenv TZ=   -8:"; // 3 spaces before +
putenv("TZ=   -8");
echo date("H");
?>
====================
with putenv TZ:
Warning: date(): Cannot find any timezone setting in /cygdrive/d/www/test/test.php on line 5

with putenv TZ=GMT:10
with putenv TZ=GMT-8:
Warning: date(): Cannot find any timezone setting in /cygdrive/d/www/test/test.php on line 11

with putenv TZ=   -8:
Warning: date(): Cannot find any timezone setting in /cygdrive/d/www/test/test.php on line 14
====================



i have no problem with simple test program but no idea on how to go on to trace php
int main() {}

$ gdb ./a.exe
(gdb) br main
Breakpoint 1 at 0x401056
(gdb) r
Starting program: /home/Xuefer/a.exe 

Breakpoint 1, 0x00401056 in main ()
(gdb) p (char*)getenv("TZ")
$2 = 0x4b08cb "GMT"
----------------
gcc -v
gcc version 3.4.4 (cygming special) (gdc 0.12, using dmd 0.125)
bash --version
GNU bash, version 2.05b.0(1)-release (i686-pc-cygwin)
autoconf --version
autoconf (GNU Autoconf) 2.59

http://sourceforge.net/tracker/?func=detail&atid=305470&aid=459385&group_id=5470
 [2005-07-02 21:17 UTC] nlopess@php.net
I've tried to track this problem. The problem is trigered because cygwin isnt unseting the TZ variable. it justs empty it.

So, a patch like the above works perfectly:

Index: ext/date/php_date.c
===================================================================
RCS file: /repository/php-src/ext/date/php_date.c,v
retrieving revision 1.19
diff -u -r1.19 php_date.c
--- ext/date/php_date.c 1 Jul 2005 08:59:57 -0000       1.19
+++ ext/date/php_date.c 2 Jul 2005 19:15:09 -0000
@@ -94,7 +94,7 @@
        char *env;

        env = getenv("TZ");
-       if (env) {
+       if (env && *env) {
                return env;
        }
        /* Check config setting */
 [2005-07-02 21:22 UTC] nlopess@php.net
BTW, here is why I've asked you to changed two putenv() in the tests:

<?php
echo "putenv('TZ'):\n";
putenv("TZ");
var_dump(getenv('TZ'));

echo "\nputenv('TZ='):\n";
putenv("TZ=");
var_dump(getenv('TZ'));

?>

outputs:
putenv('TZ'):
string(32) "GMTST0GMTDT-1,M3.5.0/1,M10.5.0/2" //that crap is the cygwin's default (at least on my machines)

putenv('TZ='):
string(0) ""
 [2005-07-03 13:31 UTC] nlopess@php.net
Fixed in CVS by Derick.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 11:01:30 2024 UTC