php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #62896 "DateTime->modify('+0 days')" Modifies DateTime Object
Submitted: 2012-08-22 15:30 UTC Modified: 2012-10-01 03:21 UTC
Votes:5
Avg. Score:4.4 ± 0.5
Reproduced:4 of 4 (100.0%)
Same Version:2 (50.0%)
Same OS:2 (50.0%)
From: hoang dot nguyen at groupion dot com Assigned: stas (profile)
Status: Closed Package: Date/time related
PHP Version: 5.4Git-2012-08-22 (snap) OS: Windows, Linux
Private report: No CVE-ID: None
 [2012-08-22 15:30 UTC] 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


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-30 00:49 UTC] lonnyk at gmail dot com
This seems to be related to bug #62561
 [2012-10-01 03:21 UTC] stas@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: stas
 [2012-10-01 03:21 UTC] stas@php.net
The fix for this bug has been committed.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 04:01:31 2024 UTC