Bug #78055 [Com]: DatePeriod recurrences changing after creation
| From: | mkroese at eljakim dot nl | Date: | Mon, 23 Sep 2019 10:30:31 +0000 |
| Subject: | Bug #78055 [Com]: DatePeriod recurrences changing after creation | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-222889@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78055&edit=1
ID: 78055
Comment by: mkroese at eljakim dot nl
Reported by: kb2kztynisv99h3ykx at mail dot uebernickel dot info
Summary: DatePeriod recurrences changing after creation
Status: Open
Type: Bug
Package: Date/time related
Operating System: macOS
PHP Version: 7.3.5
Block user comment: N
Private report: N
New Comment:
> - maybe that should be removed in the documentation now that getRecurrences is available?
Or the documentation of the property and/or the getter should be improved. Also, I'd expect
getRecurrences() and ->recurrences to yield the same value.
The literal documentation for the $recurrences property is:
> The number of recurrences, if the DatePeriod instance had been created by explicitly passing
> $recurrences. ***See also DatePeriod::getRecurrences().***
however the documentation regarding DatePeriod::getRecurrences() does not note any difference with
the $recurrences property.
Previous Comments:
------------------------------------------------------------------------
[2019-05-23 14:01:24] sjon@php.net
Looking at Bug #75113 - using the recurrences property is not really supported - maybe that should
be removed in the documentation now that getRecurrences is available?
------------------------------------------------------------------------
[2019-05-23 12:31:49] kb2kztynisv99h3ykx at mail dot uebernickel dot info
Description:
------------
When creating a DatePeriod object using the "recurrences" constructor, it internally
changes the counter by increasing it by 1.
As the test script illustrates the expectation would be to have the given count of iterations, but
it actually contains one more.
The documentation at https://www.php.net/manual/en/class.dateperiod.php
misses the details. My guess is some relation to the "include start date" option.
Test script:
---------------
<?php
$start = new DateTime('2018-12-31 00:00:00');
$interval = new DateInterval('P1M');
$recurrences = 5;
$period = new DatePeriod($start, $interval, $recurrences);
$dates = iterator_to_array($period);
assert($recurrences === $period->recurrences, 'The recurrences should match.');
assert($recurrences === count($dates), 'The iterator count should match the
recurrences.');
var_dump(array_map(function(DateTime $date) {
return $date->format('Y-m-d');
}, iterator_to_array($period)));
Expected result:
----------------
My expectation would be to have 5 dates even when including the start date.
Actual result:
--------------
The actual result are 6 dates within the iterator.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=78055&edit=1