Bug #73460 [Com]: Datetime add not realising it already applied DST change

From: Date: Fri, 22 Mar 2019 22:10:28 +0000
Subject: Bug #73460 [Com]: Datetime add not realising it already applied DST change
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220138@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=73460&edit=1

 ID:                 73460
 Comment by:         fyrye3 at gmail dot com
 Reported by:        saulyx at gmail dot com
 Summary:            Datetime add not realising it already applied DST
                     change
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   FreeBSD
 PHP Version:        5.6Git-2016-11-04 (Git)
 Block user comment: N
 Private report:     N

 New Comment:

Corrections to my previous comment

Example https://3v4l.org/lUaT9

Expected
-----------------------
2006-04-02 03:00 EDT
2006-04-02 01:00 EST
---
2006-10-29 01:00 EDT
2006-10-29 01:30 EDT
2006-10-29 01:00 EST
2006-10-29 01:30 EST
2006-10-29 02:00 EST
2006-10-29 02:30 EST
2006-10-29 03:00 EST


Previous Comments:
------------------------------------------------------------------------
[2019-03-22 21:56:05] fyrye3 at gmail dot com

The same endless loop issue can also be seen with DateTime::sub() when DST starts.

Example demonstrating both issues: https://3v4l.org/ZNfgq
---
<?php

date_default_timezone_set('America/New_York');

//DST starts Apr. 2nd 02:00 and moves to 03:00
$start = new \DateTime('2006-04-02T01:00:00');
$end = new \DateTime('2006-04-02T04:00:00');

while($end > $start) {
    $now = clone $end;
    $end->sub(new \DateInterval('PT1H'));
    echo $end->format('Y-m-d H:i T') . PHP_EOL;
    if ($now == $end) {
        break; //remove this will result in an endless loop
    }
}

echo '-----' . \PHP_EOL;

//DST ends Oct. 29th 02:00 and moves to 01:00
$start = new \DateTime('2006-10-29T00:30:00');
$end = new \DateTime('2006-10-29T03:00:00');

$i = 0;
while($end > $start) {
    $now = clone $start;
    $start->add(new \DateInterval('PT30M'));
    echo $start->format('Y-m-d H:i T') . PHP_EOL;
    if ($i++ > 7) {
        break; //remove this will result in an endless loop
    }
}
?>

Received
-----------------------
2006-04-02 03:00 EDT
2006-04-02 03:00 EDT
-----
2006-10-29 00:30 EDT
2006-10-29 01:00 EDT
2006-10-29 01:30 EDT
2006-10-29 01:00 EST
2006-10-29 01:30 EDT
2006-10-29 01:00 EST
2006-10-29 01:30 EDT
2006-10-29 01:00 EST
2006-10-29 01:30 EDT


Expected
-----------------------
2006-04-02 03:00 EDT
2006-04-02 01:00 EST
---
2006-10-29 00:30 EDT
2006-10-29 01:00 EDT
2006-10-29 01:30 EDT
2006-10-29 01:00 EST
2006-10-29 01:30 EST
2006-10-29 02:00 EST

------------------------------------------------------------------------
[2016-11-04 15:25:07] saulyx at gmail dot com

Description:
------------
PHP seems to run into an infinite loop when add() is run and it adjusts to the DST change, but when
it arrives at the time again, it reset back an hour for infinite amount of times. 



Test script:
---------------
$date = new DateTime('2016-11-05 22:00:00', new
DateTimeZone('America/New_York'));

foreach(range(1,48) as $i) {
	echo $date->format('Y/m/d H:i')."<br/>";
						
	$date->add(new DateInterval('PT15M'));
}

Actual result:
--------------
2016/11/05 22:00
2016/11/05 22:15
2016/11/05 22:30
2016/11/05 22:45
2016/11/05 23:00
2016/11/05 23:15
2016/11/05 23:30
2016/11/05 23:45
2016/11/06 00:00
2016/11/06 00:15
2016/11/06 00:30
2016/11/06 00:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45
2016/11/06 01:00
2016/11/06 01:15
2016/11/06 01:30
2016/11/06 01:45



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=73460&edit=1


Thread (4 messages)

« previous php.bugs (#220138) next »