php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77072 DateInterval constructor should provide a way to construct a negative interval
Submitted: 2018-10-27 17:24 UTC Modified: 2018-10-27 18:41 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:0 (0.0%)
From: teo8976 at gmail dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.3.0RC4 OS: all
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-10-27 17:24 UTC] 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"


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-10-27 18:41 UTC] requinix@php.net
-Package: PHP Language Specification +Package: Date/time related
 [2018-10-27 18:41 UTC] 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.
 
PHP Copyright © 2001-2018 The PHP Group
All rights reserved.
Last updated: Mon Dec 10 08:01:24 2018 UTC