|  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: -
Avg. Score:5.0 ± 0.0
Reproduced:4 of 4 (100.0%)
Same Version:3 (75.0%)
Same OS:3 (75.0%)
From: knutoh at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.1.9 OS: irrelevant
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2017-09-07 11:42 UTC] knutoh at gmail dot com
This change in this commit:;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:

Actual result:


0 (last revision 2018-07-19 09:44 UTC) by )

Add a Patch

Pull Requests

Add a Pull Request


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.

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.
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Thu Jul 19 09:01:25 2018 UTC