|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2012-10-19 12:30 UTC] 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
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Dec 01 04:00:01 2025 UTC |
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:00Experiencing the same thing on PHP 5.4.26 (RHEL 5.6) when subtracting an hour at the time across DST boundary. Test script: --------------- // Init DateTime after DST change $dt = new DateTime('2014-03-30 05:03:00', new DateTimeZone('Europe/Berlin')); $di = new DateInterval('PT1H'); // Subtract one hour each time and notice how time is stuck echo $dt->format('Y-m-d H:i:s') . "\n"; $dt->sub($di); echo $dt->format('Y-m-d H:i:s') . "\n"; $dt->sub($di); echo $dt->format('Y-m-d H:i:s') . "\n"; $dt->sub($di); echo $dt->format('Y-m-d H:i:s') . "\n"; $dt->sub($di); echo $dt->format('Y-m-d H:i:s') . "\n"; Result: ----------------- 2014-03-30 05:03:00 2014-03-30 04:03:00 2014-03-30 03:03:00 2014-03-30 03:03:00 2014-03-30 03:03:00 2014-03-30 03:03:00