Bug #63615 [Asn->Wfx]: DateTime::modify() ignores timezone
| From: | heiglandreas@php.net | Date: | Sun, 19 Mar 2017 10:58:34 +0000 |
| Subject: | Bug #63615 [Asn->Wfx]: DateTime::modify() ignores timezone | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-207943@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63615&edit=1
ID: 63615
Updated by: heiglandreas@php.net
Reported by: flavius dot as at gmail dot com
Summary: DateTime::modify() ignores timezone
-Status: Assigned
+Status: Wont fix
Type: Bug
Package: Date/time related
Operating System: Linux x64
PHP Version: 5.4.9
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
DateTime::modify is supposed to be used to modify an existing datetime-object in respect to date and
or time. If you want to modify the timezone use "DateTimeInterface::setTimezone()" and if
you want to set a new DateTime use "new DateTime()".
Previous Comments:
------------------------------------------------------------------------
[2013-01-06 16:26:58] derick@php.net
The original idea behind modify was to only add specific hours, minutes, days etc. and not to *set*
specific values such as timezones (or year, month, etc). I am therefore leaning to saying to this
patch: "this is not how things are supposed to work".
------------------------------------------------------------------------
[2012-11-26 21:42:36] flavius dot as at gmail dot com
Description:
------------
DateTime::modify() ignores the timezone (when using the RFC 2822 format for instance).
The right timestamp should be $t1 (from the example below).
Test script:
---------------
<?php
$str = "Tue, 10 Apr 2012 11:27:56 +0300";
$d1 = new DateTime($str);
$d2 = new DateTime;
$d2->modify($str);
$t1 = $d1->getTimestamp();
$t2 = $d2->getTimestamp();
$tz1 = $d1->getTimezone()->getName();
$tz2 = $d2->getTimezone()->getName();
$f1 = $d1->format(DateTime::RFC2822);
$f2 = $d2->format(DateTime::RFC2822);
var_dump(compact('t1', 't2', 'tz1', 'tz2', 'f1',
'f2'));
/*
array(6) {
't1' =>
int(1334046476)
't2' =>
int(1334050076)
'tz1' =>
string(6) "+03:00"
'tz2' =>
string(13) "Europe/Vienna"
'f1' =>
string(31) "Tue, 10 Apr 2012 11:27:56 +0300"
'f2' =>
string(31) "Tue, 10 Apr 2012 11:27:56 +0200"
}
*/
Expected result:
----------------
$t1 == $t2
Actual result:
--------------
$t1 != $t2
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63615&edit=1