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

From: Date: Tue, 02 May 2017 20:06:01 +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-208917@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:            Date/time related
 Operating System:   Ubuntu 16.04.2 LTS
 PHP Version:        7.1.4
 Block user comment: N
 Private report:     N

 New Comment:

Thanks Derick!
gonna rework my pull request


Previous Comments:
------------------------------------------------------------------------
[2017-05-02 12:34:14] derick@php.net

Andrew, it might look fixed for you because you have a different timezone with different DST rules
configured.

------------------------------------------------------------------------
[2017-05-02 12:12:51] andrew dot nester dot dev at gmail dot com

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)

------------------------------------------------------------------------
[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


Thread (8 messages)

« previous php.bugs (#208917) next »