Bug #52015 [Com]: Ending date is ignored while iterating DatePeriod
| From: | boogerlad at gmail dot com | Date: | Wed, 29 Jan 2014 11:38:12 +0000 |
| Subject: | Bug #52015 [Com]: Ending date is ignored while iterating DatePeriod | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-184072@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=52015&edit=1
ID: 52015
Comment by: boogerlad at gmail dot com
Reported by: ko dot fivestar at gmail dot com
Summary: Ending date is ignored while iterating DatePeriod
Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Ubuntu 10.04
PHP Version: 5.3.2
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
Now that this option exists, how would you use both DatePeriod::EXCLUDE_START_DATE and
DatePeriod::INCLUDE_END_DATE?
Previous Comments:
------------------------------------------------------------------------
[2010-06-07 16:03:49] degeberg@php.net
The following patch has been added/updated:
Patch Name: php_bug52015.diff
Revision: 1275919428
URL: http://bugs.php.net/patch-display.php?bug=52015&patch=php_bug52015.diff&revision=1275919428
------------------------------------------------------------------------
[2010-06-07 16:03:44] degeberg@php.net
Whether or not it's a bug is debatable. It could be considered a half-open interval (which
would then make it a documentation issue).
Changing it to a closed interval would break backwards compatibility. It would probably be better
adding one more option to DatePeriod that allows the inclusion of the end date. The attached patch
implements that.
------------------------------------------------------------------------
[2010-06-07 13:56:17] ko dot fivestar at gmail dot com
Description:
------------
When passing DateTime objects to first and third argument of DatePeriod constructor, the specified
date on the third argument is not being interated when both DateTime object contains same time
value.
After looking through ext/date/php_date.c, date_period_it_has_more() function (line 1831) had
following code:
---------------
return object->start->sse < object->end->sse ? SUCCESS : FAILURE;
---------------
While the operator "<" is currently used to compare values, operator "<="
is more appropriate for this content.
Test script:
---------------
$period = new \DatePeriod(
new \DateTime('2010-06-01'),
new \DateInterval('P1D'),
new \DateTime('2010-06-03')
);
foreach ($period as $day) {
echo $day->format('Y-m-d') . "\n";
}
Expected result:
----------------
2010-06-01
2010-06-02
2010-06-03
Actual result:
--------------
2010-06-01
2010-06-02
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=52015&edit=1