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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: sam at strictlyphp dot com
New email:
PHP Version: OS:

 

 [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

Add a Patch

Pull Requests

Add a Pull Request

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: Sat Apr 20 00:01:27 2024 UTC