php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54495 Empty DateInterval has wrong days
Submitted: 2011-04-08 17:34 UTC Modified: 2011-11-21 15:36 UTC
From: bandy dot chris at gmail dot com Assigned: danielc (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.6 OS: Linux, x86_64
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: bandy dot chris at gmail dot com
New email:
PHP Version: OS:

 

 [2011-04-08 17:34 UTC] bandy dot chris at gmail dot com
Description:
------------
A DateInterval created with a period that spans zero days reports $days = FALSE rather than 0.

A DateInterval created by subtracting two DateTimes reports $days = 0 correctly.

Test script:
---------------
<?php

// Period of zero days, zero seconds
// $days = FALSE
print_r(new DateInterval('P0Y'));

// Difference of identical timestamps
// $days = 0
print_r(date_diff(new DateTime('@1289997296'), new DateTime('@1289997296')));

Expected result:
----------------
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 0
)
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 0
)


Actual result:
--------------
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 
)
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 0
)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-11-21 02:50 UTC] danielc@php.net
"days" is a calculated field expressing how many days are between two compared dates.  It is never set when instantiating a new date interval.  The "d" property contains the number of days specified in the interval format.  Everything is operating as expected.
 [2011-11-21 02:50 UTC] danielc@php.net
-Status: Open +Status: Bogus -Assigned To: +Assigned To: danielc
 [2011-11-21 14:24 UTC] bandy dot chris at gmail dot com
The docs are wrong in multiple places:

DateInterval::__construct() example shows [days] => 0 instead of blank/false.
DateInterval class page says if days are "unknown" the value is false.

Can these pages be updated to indicate that "days" is only valid when the object 
is created as a diff of two dates?

As far as I can tell, this means the *only* way "days" is valid is with the 
date_diff() function or DateTime::diff() method.
 [2011-11-21 15:14 UTC] derick@php.net
Yes, what you said is what the docs should say.
 [2011-11-21 15:14 UTC] derick@php.net
-Status: Bogus +Status: Open -Package: Date/time related +Package: Documentation problem
 [2011-11-21 15:36 UTC] danielc@php.net
Automatic comment from SVN on behalf of danielc
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=319638
Log: Clarify &quot;days&quot; property (closes bug #54495).
 [2011-11-21 15:36 UTC] danielc@php.net
-Status: Assigned +Status: Closed
 [2011-11-21 15:36 UTC] danielc@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 22:01:27 2024 UTC