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

From: Date: Sat, 04 May 2019 16:03:23 +0000
Subject: Bug #77969 [Opn]: DateInterval given wrong d/m values if difference has Febuary month
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-220705@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77969&edit=1

 ID:                 77969
 User updated by:    jusiacms at gmail dot com
 Reported by:        jusiacms at gmail dot com
 Summary:            DateInterval given wrong d/m values if difference
                     has Febuary month
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Windows
 PHP Version:        7.2.18
 Block user comment: N
 Private report:     N

 New Comment:

.


Previous Comments:
------------------------------------------------------------------------
[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)

« previous php.bugs (#220705) next »