Bug #78055 [NEW]: DatePeriod recurrences changing after creation

From: Date: Thu, 23 May 2019 12:31:49 +0000
Subject: Bug #78055 [NEW]: DatePeriod recurrences changing after creation
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220967@lists.php.net to get a copy of this message
From:             kb2kztynisv99h3ykx at mail dot uebernickel dot info
Operating system: macOS
PHP version:      7.3.5
Package:          Date/time related
Bug Type:         Bug
Bug description:DatePeriod recurrences changing after creation

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 bug report at https://bugs.php.net/bug.php?id=78055&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=78055&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=78055&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=78055&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=78055&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=78055&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=78055&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=78055&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=78055&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=78055&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=78055&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=78055&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=78055&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=78055&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=78055&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=78055&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=78055&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=78055&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78055&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=78055&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=78055&r=mysqlcfg



Thread (3 messages)

« previous php.bugs (#220967) next »