Bug #78452 [Ver->Csd]: diff makes wrong in hour for Asia/Tehran
| From: | derick@php.net | Date: | Tue, 06 Apr 2021 19:56:01 +0000 |
| Subject: | Bug #78452 [Ver->Csd]: diff makes wrong in hour for Asia/Tehran | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-233264@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=78452&edit=1
ID: 78452
Updated by: derick@php.net
Reported by: hamedzarei dot 7232 at gmail dot com
Summary: diff makes wrong in hour for Asia/Tehran
-Status: Verified
+Status: Closed
Type: Bug
Package: Date/time related
Operating System: linux
PHP Version: 7.3.11
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:
------------------------------------------------------------------------
[2021-01-15 13:54:37] antonino dot spampinato86 at gmail dot com
It is a documentation problem, the time -1 indicates that it is to be subtracted from the day not
covered by the month (php differs from human arithmetic and can mistakenly believe that 30 days is a
month instead it takes 31 days or vice versa https://www.php.net/manual/en/datetime.examples-arithmetic.php
), both the outputs are on the same side.
https://3v4l.org/4JSG1
------------------------------------------------------------------------
[2019-08-31 14:42:57] zhangwenchao001 at gmail dot com
<?php
It seems need to fix daylight saving time
date_default_timezone_set('America/New_York');
$date1 = new \DateTime('2019-11-05 11:47:24');
$date2 = new \DateTime('2019-10-02 12:47:24');
var_dump($date1->diff($date2));
----------------
object(DateInterval)#3 (16) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(3)
["h"]=>
int(-1)
["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(33)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
------------------------------------------------------------------------
[2019-08-31 14:36:16] zhangwenchao001 at gmail dot com
I think this is a problem in daylight saving time.
Test script:
---------------
date_default_timezone_set('Asia/Tehran');
$date1 = new \DateTime('2019-09-21 11:47:24');
$date2 = new \DateTime('2019-08-18 12:47:24');
var_dump($date1->diff($date2));
--------------
object(DateInterval)#3 (16) {
["y"]=>
int(0)
["m"]=>
int(1)
["d"]=>
int(2)
["h"]=>
int(23)
["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(33)
["special_type"]=>
int(0)
["special_amount"]=>
int(0)
["have_weekday_relative"]=>
int(0)
["have_special_relative"]=>
int(0)
}
------------------------------------------------------------------------
[2019-08-28 16:33:39] joe at manvscode dot com
Tehran is in Asia though?
------------------------------------------------------------------------
[2019-08-24 17:37:58] requinix@php.net
https://3v4l.org/94hkf
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=78452
--
Edit this bug report at https://bugs.php.net/bug.php?id=78452&edit=1