Edit report at http://pear.php.net/bugs/bug.php?id=16822&edit=1
ID: 16822
Comment by: pswanson
Reported By: patrick at populiweb dot com
Summary: setTZByID() does not behave as expected
Status: Open
Type: Bug
Package: Date
Operating System: CentOS
Package Version: 1.4.7
PHP Version: 5.2.5
New Comment:
This is because getDate(DATE_FORMAT_UNIXTIME) uses gmmktime, which
causes the date being returned to first be converted to local time. If
you change it to mktime, it should behave as expected.
Previous Comments:
------------------------------------------------------------------------
[2009-11-22 20:49:57] steve_tp
Corrections to test script.
/** Test of Date class demonstrating how setTZByID() does not work as
expected. */
include ("Date.php");
// initialize object
$timestamp = 1258918447;
$d = new Date($timestamp);
$d->setTZByID("GMT");
$timestampGMT = $d->getTime();
echo "Local Time: " . date("m/d/Y h:i:s A O", $timestamp) . " timestamp
= $timestamp <br />";
echo "Time in GMT: " . $d->format("%D %r %O") . " timestamp =
$timestampGMT <br />";
------------------------------------------------------------------------
[2009-11-22 20:34:07] steve_tp
Description:
------------
Perhaps this is an expectation problem. I instantiate a new Date object
with a timestamp $x = new Date(time());
and then set the timezone
$x->setTZByID("GMT");
I expect the timestamp to remain the same, and the date to now be
reported in GMT, but the date and time are now reported inconsistently.
Am I interpreting this wrong somehow?
Test script:
---------------
<?php
/** Test of Date class demonstrating how setTZByID() does not work as
expected.
*/
include ("/Date.php");
// initialize object
$timestamp = 1258918447;
$d = new Date($timestamp);
$d->setTZByID("GMT");
$timestampGMT = $d->getTime();
echo "Local Time: " . date("m/d/Y h:i:s A O") . " timestamp = $timestamp
<br />";
echo "Time in GMT: " . $d->format("%D %r %O") . " timestamp =
$timestampGMT <br />";
?>
Expected result:
----------------
Local Time: 11/22/2009 02:34:07 PM -0500 timestamp = 1258918447
Time in GMT: 11/22/2009 07:34:07 PM +00:00 timestamp = 1258918447
Actual result:
--------------
Local Time: 11/22/2009 02:34:07 PM -0500 timestamp = 1258918447
Time in GMT: 11/22/2009 02:34:07 PM +00:00 timestamp = 1258918447
Note: on 2nd line, timestamp and time are now inconsidtent.
------------------------------------------------------------------------