Req #79104 [Asn->Wfx]: Relative DateInterval Creates Infinite Loop
| From: | derick@php.net | Date: | Sun, 05 Jun 2022 14:31:36 +0000 |
| Subject: | Req #79104 [Asn->Wfx]: Relative DateInterval Creates Infinite Loop | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-241674@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79104&edit=1
ID: 79104
Updated by: derick@php.net
Reported by: jimbo2150 at gmail dot com
Summary: Relative DateInterval Creates Infinite Loop
-Status: Assigned
+Status: Wont fix
Type: Feature/Change Request
Package: Date/time related
PHP Version: 7.3.13
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
I am marking this as "won't fix" as this is not doable with the current architecture.
You will have to make your own loop, and use the ->modify() method more than once in each
iteration to obtain this result:
$current = new DateTimeImmutable('2020-01-01');
while ( $current < new DateTimeImmutable('2022-01-11') )
{
$current = $current->modify('monday');
echo $current->format('Y-m-d'), "\n";
$current = $current->modify('next year January 1st');
}
Previous Comments:
------------------------------------------------------------------------
[2021-07-28 13:31:54] antonino dot spampinato86 at gmail dot com
This work first Monday of next month between two date, https://3v4l.org/R8dL6
For the first link I added I'm thinking it lacks support for month properties ("first
Monday January next year"), so DatePeriod incorrectly calculates between two dates. 'next
year'.
------------------------------------------------------------------------
[2021-07-28 13:00:25] antonino dot spampinato86 at gmail dot com
DateInterval can indicate the progress of the year, while in the second form it can be applied to
the current year. In the second you can use modify or directly in the constructor, since you are not
using a range between two dates.
The progress of the year DateInterval::createFromDateString ('first Monday of January next
year');.
Specific year not supported by Dateinterval new DateTime ('first monday of January', new
DateTimeZone ("UTC")); without specifying is the same as saying the current year.
Currently DataPeriod incorrectly calculates the distance between two relative dates, expressed
previously. Fifth I ask that Dateinterval throw an exception if with that relative date.
https://3v4l.org/uJpiU
------------------------------------------------------------------------
[2021-04-06 19:23:51] derick@php.net
I'm not sure whether it is possible to do this with a one-shot advancement yet.
------------------------------------------------------------------------
[2021-02-03 17:24:34] cmb@php.net
> but the result is erratic (not sure what is being calculated)
The algorithm selects the first Monday of January of the *current*
year, and then advances 1 year. Not sure, how to categorize that.
------------------------------------------------------------------------
[2020-01-24 12:15:35] antonino dot spampinato86 at gmail dot com
observe the behavior of DateTime, this code expands the relative date for the current year while for
DatePeriod it must not expand for the current year but must use the value for the start and end
year, it means if I have a year explicitly expressed DatePeriod result must be for the year
expressed otherwise if the year is not expressed it recovers the start and end of DatePeriod.
$var = new DateTime( 'first monday of January', new DateTimeZone( "UTC" );
$display[5] = $var->format( "l Y-m-d H:i:s" );
var_dump( $display );
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=79104
--
Edit this bug report at https://bugs.php.net/bug.php?id=79104&edit=1