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

From: Date: Tue, 02 May 2017 11:03:15 +0000
Subject: Bug #74529 [NEW]: DateTime::diff seems to ignore $absolute = true
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208903@lists.php.net to get a copy of this message
From:             hrovira at seocom dot es
Operating system: Ubuntu 16.04.2 LTS
PHP version:      7.1.4
Package:          SPL related
Bug Type:         Bug
Bug description:DateTime::diff seems to ignore $absolute = true

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 bug report at https://bugs.php.net/bug.php?id=74529&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74529&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74529&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74529&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74529&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74529&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74529&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74529&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74529&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74529&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74529&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74529&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74529&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74529&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74529&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74529&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74529&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74529&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74529&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74529&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74529&r=mysqlcfg



Thread (8 messages)

« previous php.bugs (#208903) next »