php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77969 DateInterval given wrong d/m values if difference has Febuary month
Submitted: 2019-05-04 15:51 UTC Modified: 2020-07-24 09:33 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: jusiacms at gmail dot com Assigned: cmb (profile)
Status: Duplicate Package: Date/time related
PHP Version: 7.2.18 OS: *
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jusiacms at gmail dot com
New email:
PHP Version: OS:

 

 [2019-05-04 15:51 UTC] 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) }

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-05-04 16:03 UTC] jusiacms at gmail dot com
-: michal dot jusiega at gmail dot com +: jusiacms at gmail dot com
 [2019-05-04 16:03 UTC] jusiacms at gmail dot com
.
 [2020-01-20 17:19 UTC] girgias@php.net
-Assigned To: +Assigned To: derick
 [2020-07-24 09:33 UTC] cmb@php.net
-Status: Assigned +Status: Duplicate -Operating System: Windows +Operating System: * -Assigned To: derick +Assigned To: cmb
 [2020-07-24 09:33 UTC] cmb@php.net
Duplicate of bug #52480.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 16:01:29 2024 UTC