Bug #51051 [Com]: DateTime modify wrong result with DST change

From: Date: Sat, 25 Dec 2010 01:27:22 +0000
Subject: Bug #51051 [Com]: DateTime modify wrong result with DST change
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-157311@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51051&edit=1

 ID:                 51051
 Comment by:         danielc@php.net
 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
 Private report:     N

 New Comment:

I just attached a test script that covers issues in the spring and fall.


Previous Comments:
------------------------------------------------------------------------
[2010-12-25 02:26:16] danielc@php.net

The following patch has been added/updated:

Patch Name: bug51051test.php.txt
Revision:   1293240376
URL:       
http://bugs.php.net/patch-display.php?bug=51051&patch=bug51051test.php.txt&revision=1293240376

------------------------------------------------------------------------
[2010-08-24 14:34:22] glennpratt+php at gmail dot com

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

------------------------------------------------------------------------
[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


Thread (21 messages)

« previous php.bugs (#157311) next »