Edit report at https://bugs.php.net/bug.php?id=62896&edit=1
ID: 62896
Comment by: lonnyk at gmail dot com
Reported by: hoang dot nguyen at groupion dot com
Summary: "DateTime->modify('+0 days')" Modifies DateTime
Object
Status: Open
Type: Bug
Package: Date/time related
Operating System: Windows, Linux
PHP Version: 5.4Git-2012-08-22 (snap)
Block user comment: N
Private report: N
New Comment:
This seems to be related to bug #62561
Previous Comments:
------------------------------------------------------------------------
[2012-08-22 15:30:30] hoang dot nguyen at groupion dot com
Description:
------------
Calling "modify()" with a delta of 0 should not change the time, regardless of
whether a time zone was defined for the DateTime object or not, and independent
from how the object was created (from a UNIX timestamp or a date/time string
with or without time zone).
Test script:
---------------
See long version with more details and possible regressions here:
http://pastebin.com/v8RybhVh
Below is a short excerpt for the current bug.
<?php
echo "FROM TIMESTAMP, NO TZ:\n";
$date = new DateTime('@'.strtotime('2012-08-22 00:00:00 CEST'));
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
$date->modify('+0 days');
echo $date->format('Y-m-d H:i:s T').' (offset '.$date->getOffset().")\n";
?>
Expected result:
----------------
FROM TIMESTAMP, NO TZ:
2012-08-21 22:00:00 GMT+0000 (offset 0) <-- should be equal
2012-08-21 22:00:00 GMT+0000 (offset 0) <-- to this
FROM TIMESTAMP, WITH TZ:
2012-08-22 00:00:00 CEST (offset 7200)
2012-08-22 00:00:00 CEST (offset 7200)
FROM STRING:
2012-08-22 00:00:00 CEST (offset 7200)
2012-08-22 00:00:00 CEST (offset 7200)
Actual result:
--------------
Output from PHP 5.4.4, 5.4.6 and snapshot r4e56105 from August 22, 2012:
FROM TIMESTAMP, NO TZ:
2012-08-21 22:00:00 GMT+0000 (offset 0) <-- different
2012-08-21 23:00:00 GMT+0000 (offset 0) <-- from this
FROM TIMESTAMP, WITH TZ:
2012-08-22 00:00:00 CEST (offset 7200)
2012-08-22 00:00:00 CEST (offset 7200)
FROM STRING:
2012-08-22 00:00:00 CEST (offset 7200)
2012-08-22 00:00:00 CEST (offset 7200)
In PHP 5.2.0, the bug appears when creating DateTime from a string (with time
zone), which one might test as well to guard against similar bugs:
FROM TIMESTAMP, NO TZ:
2012-08-21 22:00:00 GMT+0100 (offset 7200)
2012-08-21 22:00:00 GMT+0100 (offset 7200)
FROM TIMESTAMP, WITH TZ:
2012-08-22 00:00:00 CEST (offset 7200)
2012-08-22 00:00:00 CEST (offset 7200)
FROM STRING:
2012-08-22 00:00:00 CEST (offset 7200) <-- different
2012-08-21 23:00:00 CEST (offset 7200) <-- from this
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62896&edit=1