From:
Operating system: Linux
PHP version: 5.3.6
Package: Date/time related
Bug Type: Bug
Bug description:Incorrect results when operating with time on DST changes
Description:
------------
Incorrect results when operating with time on DST changes.
Operations like: '-1 hour', '-1 min' or setTime()
In order to resolve the problem, all operations with time must be done in
timestamp directly.
Test script:
---------------
// 2011-03-27, 02:00:00 -> 03:00:00
$tz = new DateTimezone('Europe/Madrid');
$d = new DateTime('2011-03-28 02:30:00',$tz);
// OK
// One day early
// Result: 2011-03-27 03:30:00
echo $d->modify('-1 day')->format('Y-m-d H:i:s').'<br/>';
// BAD
// One hour early (or other TIME operation)
// Expected: 2011-03-27 01:30:00, Actual: 2011-03-27 03:30:00
echo $d->modify('-1 hour')->format('Y-m-d H:i:s').'<br/>';
// BAD
// SetDate and setTime
// Expected: 2011-03-27 03:30:00, Actual: 2011-03-27 02:30:00
echo $d->setDate(2011,3,27)->setTime(2,30,0)->format('Y-m-d
H:i:s').'<br/>';
// OK
// Set timezone again after setDate and setTime fix the above problem
// Result: 2011-03-27 03:30:00
echo
$d->setDate(2011,3,27)->setTime(2,30,0)->setTimezone($tz)->format('Y-m-d
H:i:s').'<br/>';
// OK
// One hour early but changing timestamp
// Result: 2011-03-27 01:30:00
echo $d->setTimestamp(($d->getTimestamp()-3600))->format('Y-m-d
H:i:s').'<br/>';
// OK
// One hour after
// Result: 2011-03-27 03:30:00
echo $d->modify('2011-03-27 01:30:00')->modify('+1 hours')->format('Y-m-d
H:i:s').'<br/>';
// BAD
// Two hours after
// Expected: 2011-03-27 04:30:00, Actual: 2011-03-27 03:30:00
echo $d->modify('2011-03-27 01:30:00')->modify('+2 hours')->format('Y-m-d
H:i:s').'<br/>';
Expected result:
----------------
2011-03-27 03:30:00
2011-03-27 01:30:00
2011-03-27 03:30:00
2011-03-27 03:30:00
2011-03-27 01:30:00
2011-03-27 03:30:00
2011-03-27 04:30:00
Actual result:
--------------
2011-03-27 03:30:00
2011-03-27 03:30:00
2011-03-27 02:30:00
2011-03-27 03:30:00
2011-03-27 01:30:00
2011-03-27 03:30:00
2011-03-27 03:30:00
--
Edit bug report at http://bugs.php.net/bug.php?id=54799&edit=1
--
Try a snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=54799&r=trysnapshot52
Try a snapshot (PHP 5.3):
http://bugs.php.net/fix.php?id=54799&r=trysnapshot53
Try a snapshot (trunk):
http://bugs.php.net/fix.php?id=54799&r=trysnapshottrunk
Fixed in SVN:
http://bugs.php.net/fix.php?id=54799&r=fixed
Fixed in SVN and need be documented:
http://bugs.php.net/fix.php?id=54799&r=needdocs
Fixed in release:
http://bugs.php.net/fix.php?id=54799&r=alreadyfixed
Need backtrace:
http://bugs.php.net/fix.php?id=54799&r=needtrace
Need Reproduce Script:
http://bugs.php.net/fix.php?id=54799&r=needscript
Try newer version:
http://bugs.php.net/fix.php?id=54799&r=oldversion
Not developer issue:
http://bugs.php.net/fix.php?id=54799&r=support
Expected behavior:
http://bugs.php.net/fix.php?id=54799&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=54799&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=54799&r=submittedtwice
register_globals:
http://bugs.php.net/fix.php?id=54799&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54799&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=54799&r=dst
IIS Stability:
http://bugs.php.net/fix.php?id=54799&r=isapi
Install GNU Sed:
http://bugs.php.net/fix.php?id=54799&r=gnused
Floating point limitations:
http://bugs.php.net/fix.php?id=54799&r=float
No Zend Extensions:
http://bugs.php.net/fix.php?id=54799&r=nozend
MySQL Configuration Error:
http://bugs.php.net/fix.php?id=54799&r=mysqlcfg