Bug #51051 [Com]: DateTime modify wrong result with DST change
| From: | nicholas dot leon at wellsfargo dot com | Date: | Thu, 06 Oct 2016 15:54:12 +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-204514@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=51051&edit=1
ID: 51051
Comment by: nicholas dot leon at wellsfargo dot com
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:
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)
Previous Comments:
------------------------------------------------------------------------
[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
------------------------------------------------------------------------
[2013-05-30 14:56:05] joerg dot eichhorn at kiwigrid dot com
Still present with:
PHP 5.4.7 (cli) (built: Sep 12 2012 23:48:31)
Copyright (c) 1997-2012 The PHP Group
My former test script still shows the error:
<?php
$dt = new DateTime('now', new DateTimeZone('Europe/Berlin'));
// try to set timestamp of 2010-10-31T02:00:00+0200
$dt->setTimestamp(1288483200);
echo "Expected: 1288483200\n";
// but returns timestamp of 2010-10-31T02:00:00+0100
echo "Actual : ".$dt->getTimestamp()."\n"; // outputs 1288486800
?>
Any Ideas when this issue is going to be fixed? It's a serious issue that it returns another
timestamp than what was set!
------------------------------------------------------------------------
[2013-03-19 18:09:02] kavi at postpro dot net
This is still broken in 5.3.21, according to danielc's test.
$ php --version
PHP 5.3.21 (cli) (built: Jan 17 2013 12:34:34)
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2013 Zend Technologies
$ php derp.php
SPRING INTERVALS (add okay, sub does not change hour)
2010-03-14T01:59:59-05:00 America/New_York EST 0 1268549999
Adding interval: PT1S
2010-03-14T03:00:00-04:00 America/New_York EDT 1 1268550000
Subtracting interval: PT1S
2010-03-14T03:59:59-04:00 America/New_York EDT 1 1268553599
SPRING TIMESTAMPS (works as expected)
2010-03-14T01:59:59-05:00 America/New_York EST 0 1268549999
Adding seconds: 1
2010-03-14T03:00:00-04:00 America/New_York EDT 1 1268550000
Subtracting seconds: 1
2010-03-14T01:59:59-05:00 America/New_York EST 0 1268549999
FALL INTERVALS (add and sub skip the 1am - 2am redo)
2010-11-07T00:59:59-04:00 America/New_York EDT 1 1289105999
Adding interval: PT1H
2010-11-07T01:59:59-04:00 America/New_York EDT 1 1289109599
Adding interval: PT1S
2010-11-07T02:00:00-05:00 America/New_York EST 0 1289113200
Subtracting interval: PT1S
2010-11-07T01:59:59-04:00 America/New_York EDT 1 1289109599
FALL TIMESTAMPS (works as expected)
2010-11-07T00:59:59-04:00 America/New_York EDT 1 1289105999
Adding seconds: 3600
2010-11-07T01:59:59-04:00 America/New_York EDT 1 1289109599
Adding seconds: 1
2010-11-07T01:00:00-05:00 America/New_York EST 0 1289109600
Adding seconds: 3600
2010-11-07T02:00:00-05:00 America/New_York EST 0 1289113200
Subtracting seconds: 1
2010-11-07T01:59:59-05:00 America/New_York EST 0 1289113199
------------------------------------------------------------------------
[2012-05-17 00:12:04] kavi at postpro dot net
See also:
https://bugs.php.net/bug.php?id=60960
https://bugs.php.net/bug.php?id=61530
https://bugs.php.net/bug.php?id=52480
Quoting https://wiki.php.net/rfc/datetime_and_daylight_saving_time
-- "Getting
these issues straightened out before 5.4 goes into Release Candidate status seems
wise."
------------------------------------------------------------------------
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