|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80913 DateTime(Immutable)::sub around DST yield incorrect time
Submitted: 2021-03-29 07:43 UTC Modified: 2021-04-06 19:57 UTC
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: acm at tweakers dot net Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.4 OS: all
Private report: No CVE-ID: None
 [2021-03-29 07:43 UTC] acm at tweakers dot net
DateTimeImmutable and DateTime with a time like '2021-03-28 03:00:00' in 'Europe/Amsterdam' (i.e. the moment of the DST-transition) will give the wrong time when substracting less than an hour. 

The same goes for all times that will give a result within an hour from 03:00+02:00.

I.e. when substracting 30 minutes, you get the same time as when _adding_ (+60-30 = ) 30 minutes.

And the same when using DateTimeImmutable. The before-output should be 01:30+01:00. (DateTimeImmutable) (DateTime)

Btw substracting 60 minutes gives the exact same time again (03:00:00+02:00), while substracting 61 minutes correctly gives "2021-03-28T00:59:00+01:00".

Test script:
$date = new DateTime('2021-03-28 03:00:00', new DateTimeZone('Europe/Amsterdam'));
$_30mbefore = (clone $date)->sub(new DateInterval('PT30M'));
$_30mafter = (clone $date)->add(new DateInterval('PT30M'));


Expected result:
string(25) "2021-03-28T03:00:00+02:00"
string(25) "2021-03-28T01:30:00+01:00" (correct)
string(25) "2021-03-28T03:30:00+02:00"

Actual result:
string(25) "2021-03-28T03:00:00+02:00"
string(25) "2021-03-28T03:30:00+02:00" (incorrect)
string(25) "2021-03-28T03:30:00+02:00"


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-29 16:00 UTC]
-Status: Open +Status: Verified
 [2021-03-29 16:00 UTC]
This affects older PHP versions as well[1].  Interestingly, there
is some code which is supposed to cater to that[2], but it is not
executed since t->dst==1.

[1] <>
[2] <>
 [2021-03-29 16:16 UTC]
-PHP Version: 8.0.3 +PHP Version: 7.4
 [2021-03-31 16:34 UTC]
This appears to be related to bug #60960, and might even have the
same root cause.
 [2021-03-31 17:38 UTC]
Appears to be related to bug #73460 as well.
 [2021-04-06 19:57 UTC]
-Status: Verified +Status: Closed -Assigned To: +Assigned To: derick
 [2021-04-06 19:57 UTC]
The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from 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: Sun Feb 25 01:01:27 2024 UTC