|  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
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
45 - 43 = ?
Subscribe to this entry?

 [2012-11-26 21:42 UTC] flavius dot as at gmail dot com
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:
$str = "Tue, 10 Apr 2012 11:27:56 +0300";

$d1 = new DateTime($str);
$d2 = new DateTime;

$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' =>
  't2' =>
  '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


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


AllCommentsChangesGit/SVN commitsRelated reports
 [2013-01-04 21:00 UTC]
-Assigned To: +Assigned To: derick
 [2013-01-06 16:26 UTC]
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]
-Status: Assigned +Status: Wont fix
 [2017-03-19 10:58 UTC]
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-2022 The PHP Group
All rights reserved.
Last updated: Mon Nov 28 01:05:53 2022 UTC