Bug #66187 [Com]: DateTime->add() incorrect on BST boundry
| From: | php-bugs at allenjb dot me dot uk | Date: | Wed, 29 Mar 2017 20:31:35 +0000 |
| Subject: | Bug #66187 [Com]: DateTime->add() incorrect on BST boundry | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-208168@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66187&edit=1
ID: 66187
Comment by: php-bugs at allenjb dot me dot uk
Reported by: andrewpate08 at hotmail dot com
Summary: DateTime->add() incorrect on BST boundry
Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Irrelevant
PHP Version: Irrelevant
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
This issue appears to be fixed as of 5.4.24 / 5.5.8: https://3v4l.org/Q1GCb
Previous Comments:
------------------------------------------------------------------------
[2017-03-19 11:16:14] heiglandreas@php.net
We're now tracking this in https://bugs.php.net/bug.php?id=74274
------------------------------------------------------------------------
[2013-12-23 11:12:06] andrewpate08 at hotmail dot com
A workround is to switch to UTC to do the arithmetic, something like...
$originalTimezone = $targetDateTime -> getTimezone();
$targetDateTime -> setTimezone(new DateTimeZone('UTC'));
$targetDateTime -> add($durationAsDateInterval); //add
$targetDateTime -> setTimezone($originalTimezone);
------------------------------------------------------------------------
[2013-11-29 22:23:07] bwoebi@php.net
http://3v4l.org/7DUjs#v530
There's effectively something wrong: 1 hour 10 mins added in code, but
from 27-10-2013 00:55:00+01:00
to 27-10-2013 02:05:00+00:00
2 hours 10 mins are added (=> timezone change is not included)
------------------------------------------------------------------------
[2013-11-27 23:01:39] andrewpate08 at hotmail dot com
Description:
------------
British summertime does not actually end until....
27-10-2013 01:59:59+01:00 (BST)
at which point, one second later it kicks back to GMT...
27-10-2013 01:00:00+00:00 (GMT)
It seems calculations involving DateTime->add() and the 'Europe/London' DateTimeZone
crossing the END of British summertime (BST) gives an incorrect result.
On the day British summertime ends it is not until 2:00AM (BST) which is 1:00AM (GMT) that clocks
switch from BST to GMT (i.e. go back from 2:00 to 1:00)
Test script:
---------------
<?php
$start = new DateTime("2013-10-27 00:55:00", new DateTimeZone('Europe/London'));
$step = DateInterval::createFromDateString("600 seconds");
echo "start = " . $start->format('d-m-Y H:i:sP') . "<br />";
$start->add($step);
echo "start = " . $start->format('d-m-Y H:i:sP') . "<br />";
?>
Expected result:
----------------
start = 27-10-2013 00:55:00+01:00
start = 27-10-2013 01:05:00+00:00
Actual result:
--------------
start = 27-10-2013 00:55:00+01:00
start = 27-10-2013 01:05:00+01:00
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66187&edit=1