From:             ruesche at fka dot de
Operating system: Windows, Linux
PHP version:      Irrelevant
Package:          Date/time related
Bug Type:         Bug
Bug description:DateTime::add() produces inconsisten results

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 bug report at https://bugs.php.net/bug.php?id=62331&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=62331&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=62331&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=62331&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=62331&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=62331&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=62331&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=62331&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=62331&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=62331&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=62331&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=62331&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=62331&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=62331&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=62331&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=62331&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=62331&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=62331&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=62331&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=62331&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=62331&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=62331&r=mysqlcfg

Reply via email to