Bug #79104 [Com]: Relative DateInterval Creates Infinite Loop
Edit report at https://bugs.php.net/bug.php?id=79104&edit=1
ID: 79104
Comment by: a at b dot c dot de
Reported by: jimbo2150 at gmail dot com
Summary: Relative DateInterval Creates Infinite Loop
Status: Open
Type: Bug
Package: Date/time related
PHP Version: 7.3.13
Block user comment: N
Private report: N
New Comment:
Looks like it can't determine how long "first Monday of January" is.
echo $fmj->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');
What numbers should it be using for those fields?
Previous Comments:
------------------------------------------------------------------------
[2020-01-11 21:42:39] jimbo2150 at gmail dot com
Description:
------------
A relative date format used in DateInterval produces and infinite loop when used with DatePeriod.
An example is looking for the first Monday in January of each year. When iterated via DatePeriod the
year will not get iterated and the correct relative date for current year keeps getting returned
creating an infinite loop.
Test script:
---------------
// Looking for every Monday of January each year
$fmj = DateInterval::createFromDateString('first Monday of January');
$period = new DatePeriod(new DateTime('2020-01-01'), $fmj, new
DateTime('2022-01-11'));
// Infinite loop, first Monday of January of current year keeps getting iterated
foreach ($period as $dt) {
var_dump($dt->format("l Y-m-d H:i:s"));
}
Expected result:
----------------
Return each first Monday of January for the next 2 years.
string(30) "Wednesday 2020-01-01 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2021-01-04 00:00:00"
string(27) "Monday 2022-01-03 00:00:00"
Actual result:
--------------
Infinite loop where each date is the first Monday of the current year's January.
string(30) "Wednesday 2020-01-01 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
string(27) "Monday 2020-01-06 00:00:00"
...
{infinite loop}
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79104&edit=1
Thread (10 messages)