php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66187 DateTime->add() incorrect on BST boundry
Submitted: 2013-11-27 23:01 UTC Modified: 2017-03-30 08:01 UTC
From: andrewpate08 at hotmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.4.23 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 you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: andrewpate08 at hotmail dot com
New email:
PHP Version: OS:

 

 [2013-11-27 23:01 UTC] 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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-11-29 22:23 UTC] bwoebi@php.net
-Status: Open +Status: Assigned -Operating System: Linux/Windows XP +Operating System: Irrelevant -Assigned To: +Assigned To: derick
 [2013-11-29 22:23 UTC] 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-12-23 11:12 UTC] 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);
 [2017-03-19 11:16 UTC] heiglandreas@php.net
We're now tracking this in https://bugs.php.net/bug.php?id=74274
 [2017-03-29 20:31 UTC] 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-30 08:01 UTC] requinix@php.net
-Status: Assigned +Status: Closed -PHP Version: Irrelevant +PHP Version: 5.4.23
 [2017-03-30 08:01 UTC] requinix@php.net
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.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Mar 14 15:01:30 2025 UTC