php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #75167 DateTime::add does only care about backward DST transition, not forward
Submitted: 2017-09-07 11:42 UTC Modified: 2021-04-06 19:55 UTC
Votes:6
Avg. Score:4.8 ± 0.4
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:3 (50.0%)
From: knutoh at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.1.9 OS: irrelevant
Private report: No CVE-ID: None
 [2017-09-07 11:42 UTC] 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


Patches

handle-forward-dst-changeover-in-timelib (last revision 2017-09-08 05:36 UTC by knutoh at gmail dot com)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-09-07 12:06 UTC] knutoh at gmail dot com
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.
 [2021-04-06 19:55 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2021-04-06 19:55 UTC] derick@php.net
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 8.1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 21:01:29 2024 UTC