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: 2021-04-06 18:43 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: Not a bug Package: Date/time related
PHP Version: 7.3.0RC4 OS: all
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: teo8976 at gmail dot com
New email:
PHP Version: OS:

 

 [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

Pull Requests

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.
 [2019-02-11 19:25 UTC] 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
 [2021-04-06 18:43 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2021-04-06 18:43 UTC] derick@php.net
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


 [2021-04-06 20:08 UTC] php4fan at gmail dot com
This is stupid.

I know the behavior matches the documentation, but it's ridiculous nonetheless. It's a design flaw and it needs to be fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 09 20:01:28 2024 UTC