Edit report at https://bugs.php.net/bug.php?id=63311&edit=1
ID: 63311
Comment by: mas at crosscan dot com
Reported by: thomas dot mayer at 2bis10 dot de
Summary: DateTime::add() adds wrong interval when switching
from summer to winter time
Status: Open
Type: Bug
Package: Date/time related
Operating System: Windows 7, debian 6
PHP Version: 5.4.8
Block user comment: N
Private report: N
New Comment:
For me it seems not to be directly connected with switching from or to DST.
I tried the following
Test script:
----------------
date_default_timezone_set( 'Europe/Berlin' );
$date = new \DateTime( '@0' );
echo $date->format('c')."\n";
$interval = new \DateInterval( 'PT1H' );
$date->add($interval);
echo $date->format('c')."\n";
$date->add($interval);
echo $date->format('c')."\n";
Expected result:
------------------
1970-01-01T00:00:00+00:00
1970-01-01T01:00:00+00:00
1970-01-01T02:00:00+00:00
Actual result:
----------------
1970-01-01T00:00:00+00:00
1970-01-01T02:00:00+00:00
1970-01-01T04:00:00+00:00
Previous Comments:
------------------------------------------------------------------------
[2013-05-03 10:30:56] rob dot norman at infinity-tracking dot com
I'm seeing similar behaviour across daylight boundaries with CentOS 5.9, PHP
5.4.13
Test script:
------------
$tzLon = new DateTimeZone( 'Europe/London' );
$tzUtc = new DateTimeZone( 'UTC' );
$interval = new DateInterval( 'PT24H' );
// Before change from GMT to BST.
$strDt = '2013-04-31 12:00:00';
// Adding the interval in UTC behaves as expected.
$dt = new DateTime( $strDt, $tzUtc );
$dt->add( $interval );
echo $dt->format( 'Y-m-d H:i:s' ) . "\n";
// Adding the interval in Europe/London does not.
$dt = new DateTime( $strDt, $tzLon );
$dt->add( $interval );
// Convert to UTC for comparison.
$dt->setTimeZone( $tzUtc );
echo $dt->format( 'Y-m-d H:i:s' ) . "\n";
Expected result:
----------------
2013-05-02 12:00:00
2013-05-02 12:00:00
Actual result:
--------------
2013-05-02 12:00:00
2013-05-02 11:00:00
------------------------------------------------------------------------
[2012-10-19 12:33:35] [email protected]
Fix category, tak #2.
------------------------------------------------------------------------
[2012-10-19 12:32:30] thomas dot mayer at 2bis10 dot de
I switched Expected result and actual result.
Expected result:
--------------
2013-10-27T01:45:00+02:00
1382831100
2013-10-27T02:00:00+02:00
1382832000
900
Actual result:
----------------
2013-10-27T01:45:00+02:00
1382831100
2013-10-27T02:00:00+01:00
1382835600
4500
------------------------------------------------------------------------
[2012-10-19 12:31:20] [email protected]
Fix cat
------------------------------------------------------------------------
[2012-10-19 12:30:18] thomas dot mayer at 2bis10 dot de
Description:
------------
When adding an interval to a DateTime object in european summer time and the
resulting date is in european winter time, an additional hour is added.
Please note that we stay in summer time(+2) until 3:00:00 and then the clock is
set to 02:00:00 winter time(+1).
Test script:
---------------
$date = new DateTime(
'2013-10-27 01:45:00',
new DateTimeZone('Europe/Berlin')
);
$oldStamp=$date->getTimeStamp();
$interval=new DateInterval('PT15M');
echo $date->format('c')."\n";
echo $date->getTimeStamp()."\n";
$date->add($interval);
echo $date->format('c')."\n";
echo $date->getTimeStamp()."\n";
echo $date->getTimeStamp()-$oldStamp;
Expected result:
----------------
2013-10-27T01:45:00+02:00
1382831100
2013-10-27T02:00:00+01:00
1382835600
4500
Actual result:
--------------
2013-10-27T01:45:00+02:00
1382831100
2013-10-27T02:00:00+02:00
1382832000
900
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=63311&edit=1