Bug #71530 [NEW]: wrong dateTime diff results for 01.03.2016 and 01.03.2017
| From: | pawel dot zegardlo at bm dot pl | Date: | Fri, 05 Feb 2016 09:11:58 +0000 |
| Subject: | Bug #71530 [NEW]: wrong dateTime diff results for 01.03.2016 and 01.03.2017 | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-199063@lists.php.net to get a copy of this message | ||
From: pawel dot zegardlo at bm dot pl
Operating system: windows 8.1 64bit
PHP version: 5.6.18
Package: Date/time related
Bug Type: Bug
Bug description:wrong dateTime diff results for 01.03.2016 and 01.03.2017
Description:
------------
I've tested this on v5.6.15, but in changelog from 5.6.15 to 5.6.18
there is nothing about datetime so this bug seems to be not fixed also
in 5.6.18.
If we change the month in a sample code from march to april, the result
is the same for both comparisons (1 year 0 days 0 months). Also if we
change the day in sample code from 01 to 02 and stay with march, the
result is also the same. But for original code attached, the result is
different but should be also the same.
Test script:
---------------
<?php
$start = new DateTime('01.03.2016');
$end = new DateTime('01.03.2017');
$diff = $end->diff($start);
var_dump($start->format('d-m-Y'), $end->format('d-m-Y'), $diff);
$start = new DateTime('02.03.2016');
$end = new DateTime('02.03.2017');
$diff = $end->diff($start);
var_dump($start->format('d-m-Y'), $end->format('d-m-Y'), $diff);
Expected result:
----------------
string '01-03-2016' (length=10)
string '01-03-2017' (length=10)
object(DateInterval)[3]
public 'y' => int 1
public 'm' => int 0
public 'd' => int 0
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 1
public 'days' => int 365
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
string '02-03-2016' (length=10)
string '02-03-2017' (length=10)
object(DateInterval)[2]
public 'y' => int 1
public 'm' => int 0
public 'd' => int 0
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 1
public 'days' => int 365
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
Actual result:
--------------
string '01-03-2016' (length=10)
string '01-03-2017' (length=10)
object(DateInterval)[3]
public 'y' => int 0
public 'm' => int 11
public 'd' => int 28
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 1
public 'days' => int 365
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
string '02-03-2016' (length=10)
string '02-03-2017' (length=10)
object(DateInterval)[2]
public 'y' => int 1
public 'm' => int 0
public 'd' => int 0
public 'h' => int 0
public 'i' => int 0
public 's' => int 0
public 'weekday' => int 0
public 'weekday_behavior' => int 0
public 'first_last_day_of' => int 0
public 'invert' => int 1
public 'days' => int 365
public 'special_type' => int 0
public 'special_amount' => int 0
public 'have_weekday_relative' => int 0
public 'have_special_relative' => int 0
--
Edit bug report at https://bugs.php.net/bug.php?id=71530&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=71530&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=71530&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=71530&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=71530&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=71530&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=71530&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=71530&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=71530&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=71530&r=support
Expected behavior: https://bugs.php.net/fix.php?id=71530&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=71530&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=71530&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=71530&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=71530&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=71530&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=71530&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=71530&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=71530&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=71530&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=71530&r=mysqlcfg