Bug #75167 [Com]: DateTime::add does only care about backward DST transition, not forward
| From: | knutoh at gmail dot com | Date: | Thu, 07 Sep 2017 12:06:18 +0000 |
| Subject: | Bug #75167 [Com]: DateTime::add does only care about backward DST transition, not forward | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-210992@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=75167&edit=1
ID: 75167
Comment by: knutoh at gmail dot com
Reported by: knutoh at gmail dot com
Summary: DateTime::add does only care about backward DST
transition, not forward
Status: Open
Type: Bug
Package: Date/time related
Operating System: irrelevant
PHP Version: 7.1.9
Block user comment: N
Private report: N
New Comment:
Note that this is _not_ related to all the issues on the DateTime::modify function.
https://bugs.php.net/bug.php?id=74274
This bug is really simple to fix (just some lines in interval.c that needs to be copied) Most of
those others are more complex.
Previous Comments:
------------------------------------------------------------------------
[2017-09-07 11:42:15] knutoh at gmail dot com
Description:
------------
This change in this commit: http://git.php.net/?p=php-src.git;a=blobdiff;f=ext/date/lib/interval.c;h=dce62f3a2803db69af026105f8c862806c512bcf;hp=7fa1fc5c13f24c05ddae53b9fa952bca344ff318;hb=582f6e529e843b412d582023bf0270e47b1aa468;hpb=5d0c526199add0e4f054a57db29d882c8ad89a23
fixes so that DateTime::sub and DateTime::add handles DST transitions correctly. But derickr
probably just forgot to handle forward DST transition in the DateTime::add function.
Test script:
---------------
$tz = new DateTimeZone('Europe/London'); // A timezone that has DST
$five_hours_interval = new DateInterval('PT5H');
$date = new DateTime("2014-3-30 00:00:00", $tz);
// Add five hours and subtract 5 hours. The $newDate should then equal the date.
$five_hours_later = (clone $date)->add($five_hours_interval);
$newDate = (clone $five_hours_later)->sub($five_hours_interval);
echo $date->format('c') . "\n";
echo $newDate->format('c');
Expected result:
----------------
2014-03-30T00:00:00+00:00
2014-03-30T00:00:00+00:00
Actual result:
--------------
2014-03-30T00:00:00+00:00
2014-03-29T23:00:00+00:00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=75167&edit=1