Bug #52798 [Ver]: dateTime => function diff => days KO
| From: | cataphract@php.net | Date: | Wed, 08 Sep 2010 16:12:47 +0000 |
| Subject: | Bug #52798 [Ver]: dateTime => function diff => days KO | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-154185@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=52798&edit=1
ID: 52798
Updated by: cataphract@php.net
Reported by: ebinachon at pierre-vacances dot fr
Summary: dateTime => function diff => days KO
Status: Verified
Type: Bug
Package: Date/time related
Operating System: windows xp
PHP Version: 5.3.3
Assigned To: derick
Block user comment: N
New Comment:
The problem was the call to floor().
The compiler gave a warning:
"d:\users\cataphract\documents\php-trunk\ext\date\lib\interval.c(57) :
warning C4013: 'floor' undefined; assuming extern returning int"
The assumption is wrong, because it calls
double __cdecl floor(_In_ double _X);
Which takes and returns a larger type.
I removed the call to floor, which is unnecessary since it's an integer
division.
I also changed the call to abs to a call to llabs to avoid the
conversion from long long to int and then to long long again.
Previous Comments:
------------------------------------------------------------------------
[2010-09-08 18:03:46] cataphract@php.net
The following patch has been added/updated:
Patch Name: date_diff
Revision: 1283961826
URL:
http://bugs.php.net/patch-display.php?bug=52798&patch=date_diff&revision=1283961826
------------------------------------------------------------------------
[2010-09-08 17:36:02] cataphract@php.net
I can reproduce only on Windows. The exactly value varies (seems to be
garbage memory).
------------------------------------------------------------------------
[2010-09-08 17:19:52] ebinachon at pierre-vacances dot fr
Description:
------------
I have a probleme with the function diff of dateTime.
When i do a test, the "days" result is always : 6015.
All the other informations ( Y, m, d, ... ) are correct.
Have-you an idea ?
Test script:
---------------
Exemple :
$date1 = new DateTime('2010-01-01');
$date2 = new DateTime('2010-03-13');
$interval = $date2->diff($date1);
Zend_Debug::dump($interval);
//OR
Zend_Debug::dump($interval->format('%a'));
------------------
Result :
object(DateInterval)#174 (8) {
["y"] => int(0)
["m"] => int(2)
["d"] => int(12)
["h"] => int(0)
["i"] => int(0)
["s"] => int(0)
["invert"] => int(0)
["days"] => int(6015)
}
Expected result:
----------------
days => 71
Actual result:
--------------
days => 6015
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=52798&edit=1