Bug #65003 [Opn->Csd]: Wrong date diff

From: Date: Tue, 06 Apr 2021 19:52:29 +0000
Subject: Bug #65003 [Opn->Csd]: Wrong date diff
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-233250@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65003&edit=1

 ID:                 65003
 Updated by:         derick@php.net
 Reported by:        hcy321+php at yandex dot com
 Summary:            Wrong date diff
-Status:             Open
+Status:             Closed
 Type:               Bug
 Package:            Date/time related
 Operating System:   OSX
 PHP Version:        5.4.16
-Assigned To:        
+Assigned To:        derick
 Block user comment: N
 Private report:     N

 New Comment:

The fix for this bug has been committed.
If you are still experiencing this bug, try to check out latest source from https://github.com/php/php-src and re-test.
Thank you for the report, and for helping us make PHP better.

Fixed for PHP 8.1.


Previous Comments:
------------------------------------------------------------------------
[2018-03-12 15:36:40] cmb@php.net

Related To: Bug #76069

------------------------------------------------------------------------
[2014-08-11 12:03:42] ppasindud at gmail dot com

Hi
I had a similar error and check the src in intervel.c timelib_diff the date is changed to 
local or gmt

from
13-03-01
13-04-01

to
13-02-28
13-03-31

rt->d = two->d - one->d;

and makes it 1 month and 3 days 
could it be solved by only running timelib_apply_localtime if date zones are
different or else can put some other conditions to to prevent this, any other 
way to solve this, bug is for php 5.4 but exists in newer versions too.

Thanks

------------------------------------------------------------------------
[2013-06-10 12:08:08] hcy321+php at yandex dot com

Description:
------------
DateTime::diff return wrong result for first day of month.
Tested on PHP Version 5.4.10 \ 5.4.15

Test script:
---------------
<?php
date_default_timezone_set('Europe/Moscow');

$datetime1 = new DateTime('13-03-01');
$datetime2 = new DateTime('13-04-01');

$datetime3 = new DateTime('13-03-02');
$datetime4 = new DateTime('13-04-02');

$interval = $datetime2->diff($datetime1);
echo $interval->format('%m month, %d days'), '<br>'; //1 month, 3 days

$interval = $datetime4->diff($datetime3);
echo $interval->format('%m month, %d days'); //1 month, 0 days

Expected result:
----------------
1 month, 0 days
1 month, 0 days

Actual result:
--------------
1 month, 3 days
1 month, 0 days


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=65003&edit=1


Thread (3 messages)

« previous php.bugs (#233250) next »