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: 2020-07-19 02:23 UTC
Votes:9
Avg. Score:4.6 ± 0.8
Reproduced:7 of 7 (100.0%)
Same Version:4 (57.1%)
Same OS:6 (85.7%)
From: simon at welsh-au dot com Assigned:
Status: Open Package: Date/time related
PHP Version: 7.2.2 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [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

Add a Patch

Pull Requests

Add a Pull Request

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
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Fri Nov 27 12:01:23 2020 UTC