Bug #54495 [Asn->Csd]: Empty DateInterval has wrong days

From: Date: Mon, 21 Nov 2011 15:36:52 +0000
Subject: Bug #54495 [Asn->Csd]: Empty DateInterval has wrong days
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-7455@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 Updated by: danielc@php.net Reported by: bandy dot chris at gmail dot com Summary: Empty DateInterval has wrong days -Status: Assigned +Status: Closed Type: Bug Package: Documentation problem Operating System: Linux, x86_64 PHP Version: 5.3.6 Assigned To: danielc Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-11-21 15:36:07] 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:14:44] derick@php.net Yes, what you said is what the docs should say. ------------------------------------------------------------------------ [2011-11-21 14:24:25] 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 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

« previous php.doc.bugs (#7455) next »