#43003 [Opn->Asn]: Invalid timezone reported for DateTime objects constructed using a timestamp
| From: | derick@php.net | Date: | Sat, 20 Oct 2007 15:03:34 +0000 |
| Subject: | #43003 [Opn->Asn]: Invalid timezone reported for DateTime objects constructed using a timestamp | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-118759@lists.php.net to get a copy of this message | ||
ID: 43003
Updated by: derick@php.net
Reported By: post at jefago dot de
-Status: Open
+Status: Assigned
Bug Type: Date/time related
Operating System: Debian GNU/Linux
PHP Version: 5.2.4
-Assigned To:
+Assigned To: derick
Previous Comments:
------------------------------------------------------------------------
[2007-10-17 12:30:34] post at jefago dot de
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 this bug report at http://bugs.php.net/?id=43003&edit=1