php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #76032 DateTime->diff having issues with leap days for timezones ahead of UTC
Submitted: 2018-02-28 22:40 UTC Modified: 2021-04-06 19:55 UTC
Votes:10
Avg. Score:4.6 ± 0.8
Reproduced:8 of 8 (100.0%)
Same Version:5 (62.5%)
Same OS:7 (87.5%)
From: simon at welsh-au dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 7.2.2 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: simon at welsh-au dot com
New email:
PHP Version: OS:

 

 [2018-02-28 22:40 UTC] 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)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-19 02:23 UTC] carusogabriel@php.net
-Summary: DateTime->diff having issues with leap days +Summary: DateTime->diff having issues with leap days for timezones ahead of UTC
 [2021-03-24 04:34 UTC] lominum at protonmail dot com
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
 [2021-04-06 19:55 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2021-04-06 19:55 UTC] derick@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC