From: djmaze at planet dot nl
Operating system: Windows
PHP version: 5.1.6
PHP Bug Type: Date/time related
Bug description: Incorrect gmdate('U') and date_default_timezone_set()
Description:
------------
gmdate('U') shows the incorrect unix epoch.
http://php.net/gmdate: 'Format a GMT/UTC date/time'
http://php.net/date: 'U = Seconds since the Unix Epoch (January 1 1970
00:00:00 GMT)'
After calling date_default_timezone_set() everything is messed up, or is
that the whole purpose but someone forgot to document it?
Reproduce code:
---------------
<?php
function get_unixts()
{
return array(
'time()' => time(),
'date(\'U\')' => date('U'),
'date(\'Z\')' => date('Z'),
'gmtime' => (time()-date('Z')),
'gmdate(\'U\')' => gmdate('U'),
'gmdate(\'Z\')' => gmdate('Z'),
'date_default_timezone' => date_default_timezone_get(),
);
}
$def = get_unixts();
date_default_timezone_set('UTC');
$set = get_unixts();
echo '<html><body><table
border="1"><tr><td>type</td><td>normal</td><td>after set UTC</td></tr>';
foreach ($def as $t => $v)
{
echo "<tr><td>$t</td><td>$v</td><td>{$set[$t]}</td></tr>";
}
echo '</table></body></html>';
?>
Expected result:
----------------
type normal after set UTC
time() 1159732108 1159724908
date('U') 1159732108 1159724908
date('Z') 7200 0
gmtime 1159724908 1159724908
gmdate('U') 1159724908 1159724908
gmdate('Z') 0 0
Actual result:
--------------
type normal after set UTC
time() 1159732108 1159732108
date('U') 1159732108 1159732108
date('Z') 7200 0
gmtime 1159724908 1159732108
gmdate('U') 1159732108 1159732108
gmdate('Z') 0 0
--
Edit bug report at http://bugs.php.net/?id=39012&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=39012&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=39012&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=39012&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=39012&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=39012&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=39012&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=39012&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=39012&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=39012&r=support
Expected behavior: http://bugs.php.net/fix.php?id=39012&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=39012&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=39012&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=39012&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=39012&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=39012&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=39012&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=39012&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=39012&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=39012&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=39012&r=mysqlcfg