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: -
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: knutoh at gmail dot com
New email:
PHP Version: OS:

 

 [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.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC