php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #75113 adding missing DatePeriod::getRecurrences method
Submitted: 2017-08-24 11:32 UTC Modified: 2017-08-28 08:21 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:0 of 1 (0.0%)
From: nyamsprod at gmail dot com Assigned:
Status: Closed Package: Date/time related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2017-08-24 11:32 UTC] nyamsprod at gmail dot com
Description:
------------
Currently it is not possible to access the DatePeriod recurrences property when no endDate is specified.

Expected result:
----------------
$start = new DateTimeImmutable('2012-07-01');
$end = new DateTimeImmutable('2012-07-31');
$interval = new DateInterval('P7D');
$recurrences = 4;

$periodWithRecurrences = new DatePeriod($start, $interval, $recurrences);
$periodWithRecurrences->getRecurrences(); //returns 4
$periodWithRecurrences->getEndDate(); //returns null

$periodWithoutRecurrences = new DatePeriod($start, $interval, $end);
$periodWithoutRecurrences->getRecurrences(); //returns null
$periodWithoutRecurrences->getEndDate(); //returns DateTimeInterface object equivalent to $end

Actual result:
--------------
Fatal error: Uncaught Error: Call to undefined method DatePeriod::getRecurrences()

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2017-08-24 12:36 UTC] cmb@php.net
-Type: Bug +Type: Feature/Change Request
 [2017-08-24 14:49 UTC] requinix@php.net
-Status: Open +Status: Analyzed
 [2017-08-24 14:49 UTC] requinix@php.net
There are a few undocumented dynamic properties, including one for the number of recurrences (which is calculated when using an end date).
https://3v4l.org/iGAV1

But don't go using them just yet.

HHVM implements a few properties in the class definition but makes them private: $start, $interval, $end, $options, $current, $recurrances [sic], and $iterKey. PHP's properties are created on the object and not defined on the class.
- ReflectionObject: https://3v4l.org/8BKTW
- ReflectionClass: https://3v4l.org/CfZuJ

Since there's already getDateInterval, getEndDate, and getStartDate, maybe making the properties real and private and creating a getRecurrences would be best.
(HHVM does not have a getRecurr[ae]nces method either)
 [2017-08-28 08:21 UTC] nyamsprod at gmail dot com
To be honest one should definetly not rely on those undocumented properties because they are "broken" the interval property returns a DateInterval object in invalid state and the enddate/reccurences properties values sometimes are badly inferred.

That's why I thought adding getRecurrences was to be consider a bug fix since:

- it would give full access to the DatePeriod property in a standardized way.
- the others getter methods were added in a patch version of PHP5.6.
- i don't think an RFC is needed for this kind of patch given the other getter methods are already present and this addition just complement them
 [2019-03-17 18:38 UTC] derick@php.net
Automatic comment on behalf of nyamsprod@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=6eb83a63e1833f0991af4ccccc5533269c8af96c
Log: Fixed bug #75113: Added DatePeriod::getRecurrences() method.
 [2019-03-17 18:38 UTC] derick@php.net
-Status: Analyzed +Status: Closed
 [2019-03-18 08:43 UTC] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=347018
Log: Document #75113: adding missing DatePeriod::getRecurrences method
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 15:01:29 2024 UTC