Edit report at https://bugs.php.net/bug.php?id=51051&edit=1
ID: 51051
Updated by: heiglandreas@php.net
Reported by: mehdi dot rande at aliasource dot fr
Summary: DateTime modify wrong result with DST change
-Status: Assigned
+Status: Duplicate
Type: Bug
Package: Date/time related
Operating System: all
PHP Version: 7.0.8
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
We're tracking this now in https://bugs.php.net/bug.php?id=74274
Previous Comments:
------------------------------------------------------------------------
[2016-10-12 09:23:03] rado at max dot si
Still present in php 7.0.8
php -v
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
date_default_timezone_set('Europe/Ljubljana');
$d = new DateTime('2016-10-30 0000');
$oldts = $d->getTimestamp();
$newts = $d->getTimestamp() + 2 * 3600; // 2h
$d->modify("+2 hour"); // it doesn't always give the right result
$dts = $d->getTimestamp();
echo " By adding 2 hours to " . date('Y-M-d H:i:s I e', $oldts) . " we get
" . PHP_EOL;
echo " Actual result " . date('Y-M-d H:i:s I e', $newts) . PHP_EOL;
echo " Expected result " . date('Y-M-d H:i:s I e', $dts) . PHP_EOL;
By adding 2 hours to 2016-Oct-30 00:00:00 1 Europe/Ljubljana we get
Actual result 2016-Oct-30 02:00:00 1 Europe/Ljubljana
Expected result 2016-Oct-30 02:00:00 0 Europe/Ljubljana
------------------------------------------------------------------------
[2016-10-12 09:15:50] rado at max dot si
Still present in php 7.0.8
php -v
PHP 7.0.8-0ubuntu0.16.04.3 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.8-0ubuntu0.16.04.3, Copyright (c) 1999-2016, by Zend Technologies
with Xdebug v2.4.0, Copyright (c) 2002-2016, by Derick Rethans
date_default_timezone_set('Europe/Ljubljana');
$d = new DateTime('2016-10-30 0000');
$newts = $d->getTimestamp() + 2 * 3600; // 2h
$d->modify("+2 hour"); // it doesn't always give the right result
$dts = $d->getTimestamp();
echo " By adding 2 hours to " . date('Y-M-d H:i:s I e', $oldts) . " we get
" . PHP_EOL;
echo " Actual result " . date('Y-M-d H:i:s I e', $newts) . PHP_EOL;
echo " Expected result " . date('Y-M-d H:i:s I e', $dts) . PHP_EOL;
By adding 2 hours to 2017-Jan-01 01:00:00 0 Europe/Ljubljana we get
Actual result 2016-Oct-30 02:00:00 1 Europe/Ljubljana
Expected result 2016-Oct-30 02:00:00 0 Europe/Ljubljana
------------------------------------------------------------------------
[2016-10-06 15:54:05] nicholas dot leon at wellsfargo dot com
Still present in PHP 5.5.23 (cli) (built: Apr 2 2015 05:29:14)
$oDate = new DateTime("11/6/2016 1:00:00am");
print($oDate->format('Y-m-d H:i:s').PHP_EOL);
$oDate->add(new DateInterval('PT1H'));
print($oDate->format('Y-m-d H:i:s').PHP_EOL);
$ ./test2.php
2016-11-06 01:00:00
2016-11-06 01:00:00
Expected:
2016-11-06 01:00:00
2016-11-06 02:00:00 (or maybe 03:00:00 -- but definitely not 01:00:00)
------------------------------------------------------------------------
[2016-07-19 09:26:46] dasistmeine-mail at gmx dot de
This bug is still present as of PHP 7.0.5!
$date = new DateTime('2017-03-26 1:59:59', new DateTimeZone('Europe/Berlin'));
echo $date->format('Y-m-d H:i:s') . PHP_EOL;
$date->modify('+ 1 second')->modify('- 1 second');
echo $date->format('Y-m-d H:i:s') . PHP_EOL;
expected:
2017-03-26 1:59:59
2017-03-26 1:59:59
actualy got:
2017-03-26 01:59:59
2017-03-26 03:59:59
------------------------------------------------------------------------
[2016-03-13 23:52:53] cvkline at gmail dot com
This bug is still present as of PHP 5.5.25!
$gd = new DateTime('2016-03-13 03:30:00');
echo $gd->format('Y-m-d H:i:s T') . "\n";
$gd->modify('-45 minutes');
echo $gd->format('Y-m-d H:i:s T') . "\n";
produces:
2016-03-13 03:30:00 CDT
2016-03-13 03:45:00 CDT
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=51051
--
Edit this bug report at https://bugs.php.net/bug.php?id=51051&edit=1