Edit report at http://bugs.php.net/bug.php?id=51051&edit=1

 ID:                 51051
 Comment by:         glennpratt+php at gmail dot com
 Reported by:        mehdi dot rande at aliasource dot fr
 Summary:            DateTime modify wrong result with DST change
 Status:             Assigned
 Type:               Bug
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        5.3.1
 Assigned To:        derick
 Block user comment: N

 New Comment:

Correction for the Expected result above.



Expected Result

---------------

2011-03-13T03:00:00-05:00 America/Chicago

2011-03-13T01:58:00-06:00 America/Chicago


Previous Comments:
------------------------------------------------------------------------
[2010-08-24 00:04:28] glennpratt at gmail dot com

Same issue here on PHP 5.3.2



<?php



$date = new DateTime('2011-03-13T03:00:00',
timezone_open('America/Chicago'));

print($date->format('c e'));



$date->modify('-2 minutes');

print($date->format('c e'));



?>





Actual Result

-------------

2011-03-13T03:00:00-05:00 America/Chicago

2011-03-13T03:58:00-05:00 America/Chicago



Expected Result

---------------

2011-03-13T03:00:00-05:00 America/Chicago

2011-03-13T01:58:00-05:00 America/Chicago





Comparison: Ruby time library

-----------------------------

irb(main):015:0> date = Time.parse('2011-03-13T03:00:00 in CST')

=> Sun Mar 13 03:00:00 -0500 2011

irb(main):016:0> date - 120

=> Sun Mar 13 01:58:00 -0600 2011

------------------------------------------------------------------------
[2010-02-15 10:56:45] mehdi dot rande at aliasource dot fr

Sorry the expected result is  in fact the actual result, and the actual


result is the expected result.

------------------------------------------------------------------------
[2010-02-15 10:55:19] mehdi dot rande at aliasource dot fr

Description:
------------
When adding seconds (or minutes or hours) to a datetime via the modify 

method, if the date before modification is before the DST change and the


date after modification is after the DST change, the date after 

modification will be wrong.

php 5.2 seems to be affected too.

Reproduce code:
---------------
<?php

$dateBefore = new DateTime("2012-10-27 12:00:00", new
DateTimezone("Europe/Paris"));

var_dump($dateBefore->format('c'));

// DST change : 2012-10-28 01:00:00

$dateAfter = new DateTime("2012-10-28 12:00:00", new
DateTimezone("Europe/Paris"));

var_dump($dateAfter->format('c'));

$diff = $dateAfter->format('U') - $dateBefore->format('U');

var_dump($diff); // === 25 hours, 

$dateBefore->modify('+'.$diff.' seconds');

var_dump($dateBefore->format('c'));

?>

Expected result:
----------------
string(25) "2012-10-27T12:00:00+02:00"

string(25) "2012-10-28T12:00:00+01:00"

int(90000)

string(25) "2012-10-28T13:00:00+01:00"



Actual result:
--------------
string(25) "2012-10-27T12:00:00+02:00"

string(25) "2012-10-28T12:00:00+01:00"

int(90000)

string(25) "2012-10-28T12:00:00+01:00"




------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51051&edit=1

Reply via email to