Bug #77969 [NEW]: DateInterval given wrong d/m values if difference has Febuary month

From: Date: Sat, 04 May 2019 15:51:13 +0000
Subject: Bug #77969 [NEW]: DateInterval given wrong d/m values if difference has Febuary month
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220704@lists.php.net to get a copy of this message
From:             michal dot jusiega at gmail dot com
Operating system: Windows
PHP version:      7.2.18
Package:          Date/time related
Bug Type:         Bug
Bug description:DateInterval given wrong d/m values if difference has Febuary month

Description:
------------
February is usually 28 days and leap 29 days a year. The problem is that
when calling the script, we should get an equal two months instead of
one month and 28 days. The situation also has when we call for 2020,
then we will receive 1 day and 29 days. For the remaining months in
which February does not exist, DateInterval returns the correct result
as the number of months assuming the first day of the month.

The probable errors occurs in all PHP version in 7.1 + what show a
3v4l.org
https://3v4l.org/KeTaO

Test script:
---------------
<?php

$lastDate = new DateTime('2019-03-01');
$firstDate = new DateTime('2019-01-01');

$dateInterval = $lastDate->diff($firstDate);

var_dump($dateInterval);

Expected result:
----------------
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(2)
["d"]=>
int(0) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0)
["f"]=> float(0)
["weekday"]=> int(0) ["weekday_behavior"]=> int(0)
["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=>
int(59)
["special_type"]=> int(0) ["special_amount"]=> int(0)
["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

Actual result:
--------------
object(DateInterval)#3 (16) { ["y"]=> int(0) ["m"]=> int(1)
["d"]=>
int(28) ["h"]=> int(0) ["i"]=> int(0) ["s"]=> int(0)
["f"]=> float(0)
["weekday"]=> int(0) ["weekday_behavior"]=> int(0)
["first_last_day_of"]=> int(0) ["invert"]=> int(1) ["days"]=>
int(59)
["special_type"]=> int(0) ["special_amount"]=> int(0)
["have_weekday_relative"]=> int(0) ["have_special_relative"]=> int(0) }

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



Thread (3 messages)

« previous php.bugs (#220704) next »