|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78055 DatePeriod recurrences changing after creation
Submitted: 2019-05-23 12:31 UTC Modified: 2021-04-06 19:08 UTC
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: kb2kztynisv99h3ykx at mail dot uebernickel dot info Assigned: derick (profile)
Status: Assigned Package: Documentation problem
PHP Version: 7.3.5 OS: macOS
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: kb2kztynisv99h3ykx at mail dot uebernickel dot info
New email:
PHP Version: OS:


 [2019-05-23 12:31 UTC] kb2kztynisv99h3ykx at mail dot uebernickel dot info
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 misses the details. My guess is some relation to the "include start date" option.

Test script:

$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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-23 14:01 UTC]
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-09-23 10:30 UTC] mkroese at eljakim dot nl
> - 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.
 [2020-01-20 17:19 UTC]
-Assigned To: +Assigned To: derick
 [2021-04-06 19:08 UTC]
-Package: Date/time related +Package: Documentation problem
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Fri Jul 01 18:05:45 2022 UTC