From:             post at jefago dot de
Operating system: Debian GNU/Linux
PHP version:      5.2.4
PHP Bug Type:     Date/time related
Bug description:  Invalid timezone reported for DateTime objects constructed 
using a timestamp

Description:
------------
A DateTime object that is created using a timestamp (with the
"@$iTimestamp" notation) but without a explicitly given time zone (in the
constructor) invalidly reports its time zone as the default time zone,
although its time zone really is UTC. Converting it to the default time
zone corrects this behaviour.

I know that this bug is somewhat similiar to
http://bugs.php.net/bug.php?id=41912, that was marked as "bogus", but I
think the demonstration code makes it clearer that in this case it is
really buggy behaviour.

In fact, the UNIX timestamp is quite clearly defined as "the number of
seconds since 1970-01-01 00:00:00 UTC" and thus it should be time zone
independant.

Reproduce code:
---------------
$oDateTest = new DateTime("@0", new
DateTimeZone(date_default_timezone_get()));
echo "timestamp 0, constructed with default time zone
(".$oDateTest->getTimezone()->getName()."): " . $oDateTest->format("Y-m-d
H:i:s")."<br />";
$oDateTest->setTimezone(new DateTimeZone("UTC"));
echo "timestamp 0, constructed with default time zone, set to
".$oDateTest->getTimezone()->getName()." afterwards: " .
$oDateTest->format("Y-m-d H:i:s")."<br />";
$oDateTest->setTimezone(new DateTimeZone(date_default_timezone_get()));
echo "timestamp 0, constructed with default time zone, then set to UTC and
then to default time zone (".$oDateTest->getTimezone()->getName().") again:
" . $oDateTest->format("Y-m-d H:i:s")."<br />";

$oDateTest = new DateTime("@0");
echo "timestamp 0, constructed with default time zone
(".$oDateTest->getTimezone()->getName()."): " . $oDateTest->format("Y-m-d
H:i:s")."<br />";
$oDateTest->setTimezone( new DateTimeZone(date_default_timezone_get()));
echo "timestamp 0, constructed with default time zone, explicitly set to
default time zone (".$oDateTest->getTimezone()->getName().") afterwards: "
. $oDateTest->format("Y-m-d H:i:s")."<br />";


Expected result:
----------------
timestamp 0, constructed with default time zone (Europe/Berlin):
1970-01-01 01:00:00
timestamp 0, constructed with default time zone, set to UTC afterwards:
1970-01-01 00:00:00
timestamp 0, constructed with default time zone, then set to UTC and then
to default time zone (Europe/Berlin) again: 1970-01-01 01:00:00
timestamp 0, constructed with default time zone (Europe/Berlin):
1970-01-01 01:00:00
timestamp 0, constructed with default time zone, explicitly set to default
time zone (Europe/Berlin) afterwards: 1970-01-01 01:00:00

Actual result:
--------------
timestamp 0, constructed with default time zone (Europe/Berlin):
1970-01-01 00:00:00 (Either the time zone or the reported time is WRONG)
timestamp 0, constructed with default time zone, set to UTC afterwards:
1970-01-01 00:00:00
timestamp 0, constructed with default time zone, then set to UTC and then
to default time zone (Europe/Berlin) again: 1970-01-01 01:00:00
timestamp 0, constructed with default time zone (Europe/Berlin):
1970-01-01 00:00:00 (Either the time zone or the reported time is WRONG)
timestamp 0, constructed with default time zone, explicitly set to default
time zone (Europe/Berlin) afterwards: 1970-01-01 01:00:00

-- 
Edit bug report at http://bugs.php.net/?id=43003&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43003&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43003&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43003&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43003&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43003&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43003&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43003&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43003&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43003&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43003&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43003&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43003&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43003&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43003&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43003&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43003&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43003&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43003&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43003&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43003&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43003&r=mysqlcfg

Reply via email to