Bug #54495 [Bgs]: Empty DateInterval has wrong days
| From: | bandy dot chris at gmail dot com | Date: | Mon, 21 Nov 2011 14:24:25 +0000 |
| Subject: | Bug #54495 [Bgs]: Empty DateInterval has wrong days | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-165401@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=54495&edit=1
ID: 54495
User updated by: bandy dot chris at gmail dot com
Reported by: bandy dot chris at gmail dot com
Summary: Empty DateInterval has wrong days
Status: Bogus
Type: Bug
Package: Date/time related
Operating System: Linux, x86_64
PHP Version: 5.3.6
Assigned To: danielc
Block user comment: N
Private report: N
New Comment:
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.
Previous Comments:
------------------------------------------------------------------------
[2011-11-21 02:50:40] 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-04-08 17:34:08] 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
)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=54495&edit=1