Bug #52480 [Com]: Incorrect difference using DateInterval

From: Date: Mon, 28 Jan 2019 12:03:55 +0000
Subject: Bug #52480 [Com]: Incorrect difference using DateInterval
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-219248@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:         cz dot paranoiq at gmail dot com
 Reported by:        alex dot joyce at staff dot comcen dot com dot au
 Summary:            Incorrect difference using DateInterval
 Status:             Assigned
 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:

another funny behavior of diff():

```
$start = new DateTime('1922-03-26 00:00:00');
$end = new DateTime('2000-01-02 00:00:00');
echo $end->diff($start, true)->format('%Y years, %m months, %d days, %h hours, %i
minutes, %s seconds');
```

returns some minutes and seconds, although both times are exact midnight. starts to be broken on
this start date or this interval length. breaks with another start time since PHP 7.3.2RC (somewhere
in 1892)


Previous Comments:
------------------------------------------------------------------------
[2017-05-25 23:27:56] michael dot moussa at gmail dot com

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

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

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

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


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 (#219248) next »