php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #70926 Negative time period in DateInterval::createFromDateString
Submitted: 2015-11-17 08:49 UTC Modified: 2015-11-17 11:12 UTC
From: red dot led0 at gmail dot com Assigned:
Status: Not a bug Package: Date/time related
PHP Version: 5.6.15 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: red dot led0 at gmail dot com
New email:
PHP Version: OS:

 

 [2015-11-17 08:49 UTC] red dot led0 at gmail dot com
Description:
------------
Passing negative time period to DateInterval::createFromDateString causes to creating DateInterval with negative values instead setting 'invert' flag

Test script:
---------------
$period = \DateInterval::createFromDateString('-1 day');
var_dump($period->d, $period->invert);

Expected result:
----------------
int(1)
int(1)

Actual result:
--------------
int(-1)
int(0)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-11-17 11:12 UTC] derick@php.net
-Status: Open +Status: Not a bug
 [2015-11-17 11:12 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

This is correct. The "invert" property is only used when you compare two DateTime objects and the first one is after the second one.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Thu Oct 08 03:00:02 2026 UTC