Bug #62331 [Opn]: DateTime::add() produces inconsistent resultst
| From: | salathe@php.net | Date: | Fri, 15 Jun 2012 09:02:31 +0000 |
| Subject: | Bug #62331 [Opn]: DateTime::add() produces inconsistent resultst | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-171278@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=62331&edit=1
ID: 62331
Updated by: salathe@php.net
Reported by: ruesche at fka dot de
Summary: DateTime::add() produces inconsistent resultst
Status: Open
Type: Bug
Package: Date/time related
Operating System: Windows, Linux
PHP Version: Irrelevant
-Assigned To:
+Assigned To: derick
Block user comment: N
Private report: N
New Comment:
This looks like a side-effect of the changes made against bug #55253.
Previous Comments:
------------------------------------------------------------------------
[2012-06-15 08:48:06] ruesche at fka dot de
typo fixed.
------------------------------------------------------------------------
[2012-06-15 08:46:43] ruesche at fka dot de
Description:
------------
When you use a timezone with daylight saving time (like Europe/Berlin) and the date of the system
running the PHP script is in this daylight saving time (like 2012-06-15), DateTime::add() will
produce results that are off by 1 hour.
When the date on the local machine is not in the daylight saving time, the same computation will
yield the expceted results.
This bug also only appears, when the DateTime instance was created using a timestamp, so a
workaround would be the following: Instead of
$date = new DateTime(gmmktime(0, 0, 0, 1, 1, 2012));
use
$date = new DateTime('2012-01-01');
The script was tested with the following systems, all having the same problem:
- Windows XP, PHP 5.3.10
- Windows XP, PHP 5.3.13
- Windows 7, PHP 5.3.10
- Arch Linux (x86_64), PHP 5.4.3
- Debian Squeeze, PHP 5.3.10
Test script:
---------------
<?php
$oneMonth = new DateInterval('P1M');
$date = new DateTime('@'.gmmktime(0, 0, 0, 1, 1, 2012));
echo $date->format('Y-m-d H:i:s')."\n";
$date->add($oneMonth);
echo $date->format('Y-m-d H:i:s')."\n";
Expected result:
----------------
2012-01-01 00:00:00
2012-02-01 00:00:00
Actual result:
--------------
2012-01-01 00:00:00
2012-02-01 01:00:00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=62331&edit=1