Bug #78590 [Ver->Opn]: DatePeriod 0 Recurrences Throws Exception since 7.2.19

From: Date: Mon, 23 Sep 2019 20:28:59 +0000
Subject: Bug #78590 [Ver->Opn]: DatePeriod 0 Recurrences Throws Exception since 7.2.19
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-222901@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78590&edit=1 ID: 78590 Updated by: requinix@php.net Reported by: will dot baumbach at iselinc dot com Summary: DatePeriod 0 Recurrences Throws Exception since 7.2.19 -Status: Verified +Status: Open Type: Bug Package: Date/time related Operating System: Linux PHP Version: 7.2.22 Block user comment: N Private report: N Previous Comments: ------------------------------------------------------------------------ [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 ------------------------------------------------------------------------ [2019-09-23 17:04:57] requinix@php.net > Shouldn't the update be reverted from a patch version to a minor version update. > (affecting only 7.4+)? Since this > is backward incompatible update, that changes the functional behavior of DatePeriod from PHP > 5.3 to 7.2.18 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. > since 0 is an acceptable range to repeat a date period 0 means no repeating at all. If there's no repeating then there is no date range. The current stance is that no recurrences is not permitted. Are you requesting that no recurrences be supported? ------------------------------------------------------------------------ [2019-09-23 16:35:07] will dot baumbach at iselinc dot com Shouldn't the update be reverted from a patch version to a minor version update. (affecting only 7.4+)? Since this is backward incompatible update, that changes the functional behavior of DatePeriod from PHP 5.3 to 7.2.18 https://semver.org/ While updating the documentation is needed, the change will break current applications that accept a 0+ argument, forcing a refactor of the code to address the exception. It should however throw an Exception if < 0 as opposed to < 1, since 0 is an acceptable range to repeat a date period, where a negative or past date is not. For example https://3v4l.org/ReWbN $start = new DateTimeImmutable('2012-07-01'); $interval = new DateInterval('P1D'); $periodWithRecurrences = new \DatePeriod($start, $interval, $start->add($interval)); foreach($periodWithRecurrences as $date) { echo $date->format('Y-m-d') . \PHP_EOL; } echo \PHP_EOL; $periodWithRecurrences = new DatePeriod($start, $interval, 0); foreach($periodWithRecurrences as $date) { echo $date->format('Y-m-d') . \PHP_EOL; } Result 2012-07-01 2012-07-01 ------------------------------------------------------------------------ [2019-09-23 15:44:48] requinix@php.net See bug #77909 https://github.com/php/php-src/commit/7b1a4e24008f34a76c343ece735953ad5124e09f Looks like the commit put the NEWS entry in the wrong section. Could explain why it's missing from the docs. I'm leaving this as a regular non-doc bug because NEWS should probably be fixed. ------------------------------------------------------------------------ [2019-09-23 15:35:31] will dot baumbach at iselinc dot com Description: ------------ --- From manual page: https://php.net/dateperiod.construct --- As of 7.2.19+, 7.3.6+ and 7.4.0+ the DatePeriod constructor recurrences argument, no longer accepts 0. Instead an exception is thrown. This was an undocumented change in the 7.2.19 change log and on the DatePeriod documentation page. Fatal error: Uncaught Exception: DatePeriod::__construct(): The recurrence count '0' is invalid. Needs to be > 0 in /in/vjVTF:6 Stack trace: #0 /in/vjVTF(6): DatePeriod->__construct(Object(DateTimeImmutable), Object(DateInterval), 0) Test script: --------------- new \DatePeriod(new \DateTimeImmutable(), new \DateInterval('P1D'), 0); https://3v4l.org/vjVTF ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78590&edit=1

« previous php.bugs (#222901) next »