Bug #74529 [Com]: DateTime::diff seems to ignore $absolute = true

From: Date: Tue, 02 May 2017 12:12:53 +0000
Subject: Bug #74529 [Com]: DateTime::diff seems to ignore $absolute = true
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208908@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=74529&edit=1 ID: 74529 Comment by: andrew dot nester dot dev at gmail dot com Reported by: hrovira at seocom dot es Summary: DateTime::diff seems to ignore $absolute = true Status: Open Type: Bug Package: SPL related Operating System: Ubuntu 16.04.2 LTS PHP Version: 7.1.4 Block user comment: N Private report: N New Comment: thanks for reporting this issue! I tried to reproduce it on latest 7.1 build (7.1.6-dev) - working good. but anyway I decided to add test to prove that it works as expected (see my PR) Previous Comments: ------------------------------------------------------------------------ [2017-05-02 11:04:36] hrovira at seocom dot es Obviously, expected and actual results are switched :( ------------------------------------------------------------------------ [2017-05-02 11:03:12] hrovira at seocom dot es Description: ------------ DateTime::diff generates different DateInterval results depending on the order, even though $absolute param is set to true. date1->diff(date2, true) is different than date2->diff(date1, true). Please, see test script. Test script: --------------- <?php $date1 = date_create("2014-11-01 00:00:00"); $date2 = date_create("2017-05-01 04:00:00"); $diff1 = $date2->diff($date1, true); $diff2 = $date1->diff($date2, true); echo $diff1->m .' months, '.$diff1->d. ' days'; // outputs: 6 months, 0 days echo $diff2->m .' months, '.$diff2->d. ' days'; // outputs: 5 months, 30 days Expected result: ---------------- 6 months, 0 days 5 months, 30 days Actual result: -------------- 6 months, 0 days 6 months, 0 days ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=74529&edit=1

« previous php.bugs (#208908) next »