php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #68286 DateTime::sub crossing DST border starts to add
Submitted: 2014-10-22 15:41 UTC Modified: 2017-03-19 11:37 UTC
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:4 of 4 (100.0%)
Same Version:1 (25.0%)
Same OS:1 (25.0%)
From: sam at strictlyphp dot com Assigned:
Status: Duplicate Package: Date/time related
PHP Version: Irrelevant OS: Irrelevant
Private report: No CVE-ID: None
 [2014-10-22 15:41 UTC] sam at strictlyphp dot com
Description:
------------
Starting with a date in standard time and subtracting over the DST "border", suddenly adds time.
Line 5 in the actual result below seems to be wrong.
Happens in all PHP versions from 5.4.24 & 5.5.8 onwards.

Test script:
---------------
$tz = new DateTimeZone('Europe/Brussels');
$date = new DateTime('2014-10-26T03:00:00', $tz);
$interval = new DateInterval('PT30M');

for ($i = 0; $i < 5; $i++) {
	echo $date->sub($interval)->format('c e T') . PHP_EOL;
}

Expected result:
----------------
2014-10-26T02:30:00+01:00 Europe/Brussels CET
2014-10-26T02:00:00+01:00 Europe/Brussels CET
2014-10-26T02:30:00+02:00 Europe/Brussels CEST
2014-10-26T02:00:00+02:00 Europe/Brussels CEST
2014-10-26T01:30:00+02:00 Europe/Brussels CEST

Actual result:
--------------
2014-10-26T02:30:00+01:00 Europe/Brussels CET
2014-10-26T02:00:00+01:00 Europe/Brussels CET
2014-10-26T02:30:00+02:00 Europe/Brussels CEST
2014-10-26T02:00:00+02:00 Europe/Brussels CEST
2014-10-26T02:30:00+02:00 Europe/Brussels CEST

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-10-22 16:13 UTC] sam at strictlyphp dot com
http://3v4l.org/rYAob
 [2016-03-30 08:15 UTC] marc dot fricou at iadvize dot com
I think i have the same problem. I can't sub() an hour to a DateTime that is set to the DST hour :
https://3v4l.org/RJ2Df
 [2016-09-29 17:53 UTC] cmb@php.net
-Status: Open +Status: Verified -Package: *General Issues +Package: Date/time related
 [2016-09-29 17:53 UTC] cmb@php.net
Indeed, there appears to be a regression in PHP 5.4.24, which
still isn't resolved, see <https://3v4l.org/rYAob>.
 [2017-03-19 11:37 UTC] heiglandreas@php.net
-Status: Verified +Status: Duplicate
 [2017-03-19 11:37 UTC] heiglandreas@php.net
We're now tracking this in https://bugs.php.net/bug.php?id=74274
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 11 17:01:28 2024 UTC