Bug #77969 [Asn->Dup]: DateInterval given wrong d/m values if difference has Febuary month
Edit report at https://bugs.php.net/bug.php?id=77969&edit=1
ID: 77969
Updated by: cmb@php.net
Reported by: jusiacms at gmail dot com
Summary: DateInterval given wrong d/m values if difference
has Febuary month
-Status: Assigned
+Status: Duplicate
Type: Bug
Package: Date/time related
-Operating System: Windows
+Operating System: *
PHP Version: 7.2.18
-Assigned To: derick
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Duplicate of bug #52480.
Previous Comments:
------------------------------------------------------------------------
[2019-05-04 16:03:23] jusiacms at gmail dot com
.
------------------------------------------------------------------------
[2019-05-04 15:51:13] jusiacms at gmail dot com
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 this bug report at https://bugs.php.net/bug.php?id=77969&edit=1
Thread (3 messages)