Bug #52480 [Com]: Incorrect difference using DateInterval

From: Date: Thu, 25 May 2017 23:28:00 +0000
Subject: Bug #52480 [Com]: Incorrect difference using DateInterval
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-209262@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=52480&edit=1

 ID:                 52480
 Comment by:         michael dot moussa at gmail dot com
 Reported by:        alex dot joyce at staff dot comcen dot com dot au
 Summary:            Incorrect difference using DateInterval
 Status:             Re-Opened
 Type:               Bug
 Package:            Date/time related
 Operating System:   irrelevant
 PHP Version:        7.1
 Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

I have submitted a PR with a test case for this bug:

https://github.com/php/php-src/pull/2539


Previous Comments:
------------------------------------------------------------------------
[2017-03-23 17:33:25] heiglandreas@php.net

That (https://3v4l.org/1b6fj) looks like a shift of the month number to me. Derick, could you have a
look at that?

------------------------------------------------------------------------
[2017-03-20 11:44:08] requinix@php.net

Happens for March https://3v4l.org/R3LLN but not May https://3v4l.org/nblYg. DST?

------------------------------------------------------------------------
[2017-03-20 11:22:55] tomasz dot majerski at o2 dot pl

Don't close this issue. PHP 7.0.6 still not getting expected results...

$date_start = '2017-03-01';
$date_end = '2017-03-31';

DateInterval Object
(
    [y] => 0
    [m] => 1
    [d] => 2
    [h] => 0
    [i] => 0
    [s] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 30
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

------------------------------------------------------------------------
[2017-03-19 09:58:41] heiglandreas@php.net

This seems to be fixed in supported versions of PHP. Therefore I'm closing this issue.

php > $date_start = new DateTime('2010-03-01');
php >   $date_end   = new DateTime('2010-07-29');
php >
php >   $interval = $date_start->diff($date_end);
php >
php >   print_r($interval);
DateInterval Object
(
    [y] => 0
    [m] => 4
    [d] => 28
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 150
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

------------------------------------------------------------------------
[2016-11-23 07:14:51] lebeker at gmail dot com

Still got a problems:

(new DateTime('2016-10-01'))->diff((new DateTime('2016-10-31'))) // 1 month
(new DateTime('2016-11-01'))->diff((new DateTime('2016-11-30'))) // 29 days
either first should be 30 days, or the second one 1 month

(new DateTime('2016-11-01'))->diff((new DateTime('2016-12-01'))) // 30 days
but that's definitely 1 whole month

and what's more interesting
(new DateTime('2016-11-01'))->diff((new DateTime('2016-11-31'))) // 30 days
but there is no such date as '2016-11-31', but that's probably another bug.


PHP 7.0.8-0ubuntu0.16.04.3

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=52480


--
Edit this bug report at https://bugs.php.net/bug.php?id=52480&edit=1


Thread (28 messages)

« previous php.bugs (#209262) next »