php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63615 DateTime::modify() ignores timezone
Submitted: 2012-11-26 21:42 UTC Modified: 2017-03-19 10:58 UTC
Votes:2
Avg. Score:1.5 ± 0.5
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: flavius dot as at gmail dot com Assigned: derick (profile)
Status: Wont fix Package: Date/time related
PHP Version: 5.4.9 OS: Linux x64
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: flavius dot as at gmail dot com
New email:
PHP Version: OS:

 

 [2012-11-26 21:42 UTC] 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

Patches

bug_63615_patch_2_memleak_fixed (last revision 2012-12-06 15:26 UTC) by njaguar at gmail dot com)
bug_63615_fix_patch.txt (last revision 2012-12-05 22:29 UTC) by njaguar at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-04 21:00 UTC] stas@php.net
-Assigned To: +Assigned To: derick
 [2013-01-06 16:26 UTC] 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".
 [2017-03-19 10:58 UTC] heiglandreas@php.net
-Status: Assigned +Status: Wont fix
 [2017-03-19 10:58 UTC] heiglandreas@php.net
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()".
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Fri Nov 16 03:01:26 2018 UTC