Bug->Doc #78590 [Asn->Csd]: DatePeriod 0 Recurrences Throws Exception since 7.2.19

[email protected]
Newsgroups php.doc.bugs
Message-ID <[email protected]>
Edit report at https://bugs.php.net/bug.php?id=78590&edit=1

 ID:                 78590
 Updated by:         [email protected]
 Reported by:        will dot baumbach at iselinc dot com
 Summary:            DatePeriod 0 Recurrences Throws Exception since
                     7.2.19
-Status:             Assigned
+Status:             Closed
-Type:               Bug
+Type:               Documentation Problem
 Package:            Date/time related
 Operating System:   Linux
 PHP Version:        7.2.22
-Assigned To:        derick
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

Well, that ship has obviously sailed. :(  The documentation has
been updated, so there's nothing to do here.


Previous Comments:
------------------------------------------------------------------------
[2021-01-13 12:11:37] [email protected]

On further consideration, disallowing zero recurrences may have
been unfortunate.  Since nothing happened regarding this issue for
more than a year, I suggest you write to the internals mailing
list for better visibility.

Anyway, I have documented the current state now:
<http://git.php.net/?p=doc/en.git;a=commit;h=a626743ba6f7c4a3c8f1e192ee2f888035b7fe7f>.

------------------------------------------------------------------------
[2019-09-24 20:37:40] will dot baumbach at iselinc dot com

>This does not necessarily imply, though, that the final standard also allows zero recurrences.

Without purchasing the latest 2019 standard. In the 2000 final draft and 2016 draft, published in 2000 and 2019 respectively.

http://www.pvv.org/~nsaa/8601v2000.pdf
https://web.archive.org/web/20171020084445/https://www.loc.gov/standards/datetime/ISO_DIS%208601-1.pdf

"[n] represents digit(s), constituting a positive integer or zero;"
"Rn/..." 
"R/..."

Since the definition and format was specified identically in both drafts, I would say it is safe to imply it also carried over into the published 2000 and 2019 final standards.

If copyrights permit and would help the PHP community, I would gladly purchase an applicable published standard.

------------------------------------------------------------------------
[2019-09-24 10:57:37] [email protected]

Well, the ISO 8061 *draft*[1] indeed allows zero recurrences:

  recurringIndicator = "R", {digit}, "/" ;
  digit = positiveDigit | "0" ;

This does not necessarily imply, though, that the final standard
also allows zero recurrences.

[1] <https://web.archive.org/web/20171020084445/https://www.loc.gov/standards/datetime/ISO_DIS%208601-1.pdf>

------------------------------------------------------------------------
[2019-09-23 21:12:15] [email protected]

NEWS entry fixed with <http://git.php.net/?p=php-src.git;a=commit;h=ed099ab18642eb1815b43c71f3fb0326f723c69d>.  Changelog fixed with <http://git.php.net/?p=web/php.git;a=commit;h=75024ae8bbe0a284518f620ab6c07f4c53288fd2>.

------------------------------------------------------------------------
[2019-09-23 20:22:08] will dot baumbach at iselinc dot com

>If you think that PHP should change its bug-fixing process so that all fixes resulting in a behavioral change must be postponed for the next series then you should bring it up on the internals mailing list. Until then, a bug fix is a bug fix.

This wasn't just a bug-fix, this is a backward incompatible change/BC Break as was stated in the pull request, as it breaks the API.

A similar change for count($string) emitting a warning for an invalid argument, was held off for a minor version where others suggested a major version.  https://github.com/php/php-src/pull/1672

So behavioral changes causing BC breaks is not something that appears to need to be addressed.

>0 means no repeating at all. If there's no repeating then there is no date range.

Period versus Range and Recurrence versus Occurrence.
For example a calendar event that repeats zero times.
The date period would reoccur 0 (zero) times, producing a date range with a single occurrence.

The old functionality would have produced a single date for the calendar event period as I demonstrated.

return new DatePeriod($calendarDate, $repeatInterval, $repeats);

Instead repeats now has to be validated to return an Iterable or change the repeats to a DateTimeInterface instead of an integer.

if ($repeats < 1) {
   return [$calendarDate];

   //or
   $endDate = clone $calendarDate;
   
   return new \DatePeriod($calendarDate, $repeatInterval, $endDate->add($repeatInterval));
}


>The current stance is that no recurrences is not permitted. Are you requesting that no recurrences be supported?

The ISO 8601 standard permits a repetition of 0 or more, 1 or more or n times.

https://web.archive.org/web/20171020084445/https://www.loc.gov/standards/datetime/ISO_DIS%208601-1.pdf
https://web.archive.org/web/20171020085148/https://www.loc.gov/standards/datetime/ISO_DIS%208601-2.pdf


"
Repetition (0 or more): {...}
Repetition (1 or more): {...}-
Repetition (n times): n * ...
"


If PHP is adhering to the ISO standards, then a repetition of 0 or more should be supported.

It appears the bug was with either the ISO 8601 repeating interval specification parsing not accepting zero recurrences or the new DatePeriod::getRecurrences() feature in 7.2.17 returning NULL instead of 0. https://3v4l.org/E8MT8

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=78590


--
Edit this bug report at https://bugs.php.net/bug.php?id=78590&edit=1
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.