Req #40743 [ReO->Nab]: DateTime ignores the TimeZone object passed to the constructor
| From: | heiglandreas@php.net | Date: | Sun, 19 Mar 2017 09:48:49 +0000 |
| Subject: | Req #40743 [ReO->Nab]: DateTime ignores the TimeZone object passed to the constructor | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207931@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=40743&edit=1
ID: 40743
Updated by: heiglandreas@php.net
Reported by: ddb at bitxtender dot de
Summary: DateTime ignores the TimeZone object passed to the
constructor
-Status: Re-Opened
+Status: Not a bug
Type: Feature/Change Request
Package: Date/time related
Operating System: all
PHP Version: 7.1
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
Initializing a DateTime-Object with a timestamp sets the Timezone to UTC, as "The unix time
stamp is a way to track time as a running total of seconds. This count starts at the Unix Epoch on
January 1st, 1970 at UTC". So this is expected behaviour and therefore not a bug.
Previous Comments:
------------------------------------------------------------------------
[2016-05-23 06:32:57] heiglandreas@php.net
IMHO there should be a difference in handling the timezone-information in the $time-parameter and
the $timezone-parameter.
Regard this snippet:
$date = new DateTime('2016-10-30 02:30:00+02:00', new
DateTimeZone('Europe/Berlin'))
$date = new DateTime('2016-10-30 02:30:00+01:00', new
DateTimeZone('Europe/Berlin'))
They ignore the $timezone-parameter even though that's the important thing IN THIS SPECIAL CASE
as it's the double hour during falling back from DST to default offset. In this case the
$timezone-parameter should be used to know that we're talking about one and the same timezone
but different hours. The other way would be to use the (at least in germany used) notation of
'20016-10-30 02A:30:00' or '20016-10-30 02B:30:00' for the first and the second
occurence of the hour between 02:00H and 03:00H.
------------------------------------------------------------------------
[2013-01-07 18:52:23] kavi at postpro dot net
Yes, it's a feature request for PHP to not soldier on without objection in a situation that is
quite likely to be involved in a logic error. This should be an E_WARNING at minimum.
------------------------------------------------------------------------
[2013-01-06 16:13:39] derick@php.net
It's still not a bug, so changing it to a feature request. The "@" acts as a timezone
specifier and if there is one of those in the string to parse, then a passed in timezone
doesn't override this. This works the same as:
$a = new DateTime("2013-01-06 16:12 CEST", new DateTimeZone("Asia/Tokyo"));
var_dump( $a );
which shows:
class DateTime#1 (3) {
public $date =>
string(19) "2013-01-06 16:12:00"
public $timezone_type =>
int(2)
public $timezone =>
string(4) "CEST"
}
------------------------------------------------------------------------
[2012-05-17 19:29:38] cataphract@php.net
Still present in master.
<?php
$dt = new DateTime('@' . time(), new DateTimeZone('Europe/Berlin'));
var_dump($dt, $dt->getTimeZone()->getName());
object(DateTime)#1 (3) {
["date"]=>
string(19) "2012-05-17 19:29:15"
["timezone_type"]=>
int(1)
["timezone"]=>
string(6) "+00:00"
}
string(6) "+00:00"
------------------------------------------------------------------------
[2012-02-09 02:28:58] kavi at postpro dot net
This bug is NOT fixed on 5.3.3 or trunk.
$ php
<?php
$a = new DateTime('Monday, 15-Aug-05 15:52:01 PDT', new
DateTimeZone('America/New_York'));
print_r($a);
DateTime Object
(
[date] => 2005-08-15 15:52:01
[timezone_type] => 2
[timezone] => PDT
)
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=40743
--
Edit this bug report at https://bugs.php.net/bug.php?id=40743&edit=1