ID: 40743
Comment by: artur at jedlinski dot pl
Reported By: ddb at bitxtender dot de
Status: Assigned
Bug Type: Date/time related
Operating System: Win XP
PHP Version: 5.2.1
Assigned To: derick
New Comment:
It is ignoring the #2 parameter when you put the timezone info inside
the #1. It's *absolutely* unacceptable.
// Europe/Warsaw = GMT +0200
$dateSrc = '2007-04-19 12:50:00 GMT';
$dateTime = new DateTime($dateSrc, new DateTimeZone('Europe/Warsaw'));
echo $dateTime->format('H:i:s')."<br />";
// RESULT: 12:50:00 (expected: 14:50:00)
$dateTime->setTimeZone(new DateTimeZone('Europe/Warsaw'));
echo $dateTime->format('H:i:s')."<br />";
// RESULT: 14:50:00 (correct)
IMHO the most intuitive way is to create the date based on the #1, but
displays it using #2.
It's not only strange it ignores #2, but in fact it's strange that the
internal DateTime pointer is set to timezone provided in #1 at all. If
the date_default_timezone_set() was set to some TZ, it should create
dates within this timezone if one doesn't state otherwise (using #2). Of
course the timezone info from #1 should be used, but only to calculate
the actual timestamp.
date_default_timezone_set('Europe/Warsaw');
$dateSrc = '2007-04-19 12:50:00 GMT';
$dateTime = new DateTime($dateSrc);
echo $dateTime->format('H:i:s')."<br />";
// RESULT: 12:50:00 (expected: 14:50:00)
Currently, it's pretty complicated to translate dates from one timezone
to another - you have to use DateTime::setTimeZone(), when one line
should do the thing:
$dateTime = new DateTime($dateWithSrcTimeZone, $timeZoneToDisplay);
(or even without $timeZoneToDisplay if you want to use your current
TZ).
Previous Comments:
------------------------------------------------------------------------
[2007-04-11 14:45:46] [EMAIL PROTECTED]
It's not totally ignored, but something fishy is going on. See the
following script + output:
<?php
$dt = new DateTime();
echo $dt->format(DATE_RFC822 . " e T O"), "\n";
$dt = new DateTime('@' . time());
echo $dt->format(DATE_RFC822 . " e T O"), "\n";
$dt = new DateTime('@' . time(), new DateTimeZone('Europe/Berlin'));
echo $dt->format(DATE_RFC822 . " e T O"), "\n";
?>
Wed, 11 Apr 07 16:42:40 +0200 Europe/Oslo CEST +0200
Wed, 11 Apr 07 14:42:40 +0100 Europe/Oslo GMT+0100 +0100
Wed, 11 Apr 07 14:42:40 +0100 Europe/Berlin GMT+0100 +0100
------------------------------------------------------------------------
[2007-03-06 23:27:24] ddb at bitxtender dot de
Description:
------------
when you create a new DateTime object the timezone object you pass
along in the constructor is ignored.
setting the timezone using setTimeZone works as expected.
also tested with 5.2-dev and 6.0-dev
Reproduce code:
---------------
$dt = new DateTime('@' . time(), new DateTimeZone('Europe/Berlin'));
echo $dt->format(DATE_RFC822);
Expected result:
----------------
Tue, 07 Mar 07 01:22:55 +0100
Actual result:
--------------
Tue, 07 Mar 07 00:22:55 +0000
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=40743&edit=1