Bug #77072 [Opn->Nab]: DateInterval constructor should provide a way to construct a negative interval
| From: | derick@php.net | Date: | Tue, 06 Apr 2021 18:43:36 +0000 |
| Subject: | Bug #77072 [Opn->Nab]: DateInterval constructor should provide a way to construct a negative interval | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233240@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77072&edit=1
ID: 77072
Updated by: derick@php.net
Reported by: teo8976 at gmail dot com
Summary: DateInterval constructor should provide a way to
construct a negative interval
-Status: Open
+Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: all
PHP Version: 7.3.0RC4
Block user comment: N
Private report: N
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
Previous Comments:
------------------------------------------------------------------------
[2019-02-11 19:25:54] duncan3dc@php.net
It is actually possible to set the invert property when constructing with 2 dates:
https://3v4l.org/v3KDQ
So a second $invert argument on the constructor would be weird in this scenario. I don't think
this should be added
------------------------------------------------------------------------
[2018-10-27 18:41:46] requinix@php.net
ISO 8601's syntax does not support negative intervals so PHP shouldn't either, but the
constructor could have a second $inverted=0 argument.
------------------------------------------------------------------------
[2018-10-27 17:24:01] teo8976 at gmail dot com
Description:
------------
A DateInterval object can represent negative intervals, when its $invert property equals 1.
However, there's no way (or no documented way) to construct a DateInterval object that is
inverted with the constructor.
Yoy need to do:
$interval = new DateInterval("whatever");
$interval->inverted = 1;
It's absolutely ridiculous and pathetic that there exist values that can be represented by the
class but cannot be created with the constructor.
The interval_spec should support a way to specify inverted intervals.
Any of these would be fine, it's just a matter of taste:
- prefix the interval with a "-" (minus) sign
e.g. "-P1Y3D"
- a "-" (minus) sign after the initial P
e.g. "P-1Y3D"
- some suffix at the end, for example "I" for "Inverted"
e.g. "P1Y3DN"
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77072&edit=1