Bug #76032 [Com]: DateTime->diff having issues with leap days for timezones ahead of UTC
| From: | lominum at protonmail dot com | Date: | Wed, 24 Mar 2021 04:34:52 +0000 |
| Subject: | Bug #76032 [Com]: DateTime->diff having issues with leap days for timezones ahead of UTC | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-232955@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=76032&edit=1
ID: 76032
Comment by: lominum at protonmail dot com
Reported by: simon at welsh-au dot com
Summary: DateTime->diff having issues with leap days for
timezones ahead of UTC
Status: Open
Type: Bug
Package: Date/time related
Operating System: Linux
PHP Version: 7.2.2
Block user comment: N
Private report: N
New Comment:
This also happens for simple month calculations:
A diff with 2021-03-01 to 2021-06-01 results in 3 months and 3 days
https://3v4l.org/HqGMh
Changing this to 2021-03-02 to 2021-06-02 results in a correct 3 months and 0 days
https://3v4l.org/KlM3m
Previous Comments:
------------------------------------------------------------------------
[2018-02-28 22:40:54] simon at welsh-au dot com
Description:
------------
When in a timezone that's ahead of UTC, DateTime->diff seems to have issues when the
starting date falls on a leap day in UTC.
In the test script, changing the dates from March 1 to March 2 has both var_dump calls showing 10.
Test script:
---------------
<?php
date_default_timezone_set('UTC');
$d = new DateTime('2008-03-01');
$a = new DateTime('2018-03-01');
var_dump($d->diff($a)->y);
date_default_timezone_set('Europe/Amsterdam');
$d = new DateTime('2008-03-01');
$a = new DateTime('2018-03-01');
var_dump($d->diff($a)->y);
Expected result:
----------------
int(10)
int(10)
Actual result:
--------------
int(10)
int(9)
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=76032&edit=1