Bug #66187 [Asn->Csd]: DateTime->add() incorrect on BST boundry

[email protected]
Newsgroups php.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=66187&edit=1

 ID:                 66187
 Updated by:         [email protected]
 Reported by:        andrewpate08 at hotmail dot com
 Summary:            DateTime->add() incorrect on BST boundry
-Status:             Assigned
+Status:             Closed
 Type:               Bug
 Package:            Date/time related
 Operating System:   Irrelevant
-PHP Version:        Irrelevant
+PHP Version:        5.4.23
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

Indeed, looks like it was fixed in 2013 during
  https://github.com/php/php-src/commit/582f6e529e843b412d582023bf0270e47b1aa468

Note that the Oct 2013 DST transition was at 2am local time (1am UTC and /London was in UTC+1) so the original test script is inaccurate; @bwoebi's version repros the bug.


Previous Comments:
------------------------------------------------------------------------
[2017-03-29 20:31:35] php-bugs at allenjb dot me dot uk

This issue appears to be fixed as of 5.4.24 / 5.5.8: https://3v4l.org/Q1GCb

------------------------------------------------------------------------
[2017-03-19 11:16:14] [email protected]

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] [email protected]

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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.