php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81263 Wrong result from DateTimeImmutable::diff
Submitted: 2021-07-15 21:32 UTC Modified: 2021-08-08 11:18 UTC
From: mail at gh01 dot de Assigned:
Status: Duplicate Package: Date/time related
PHP Version: master-Git-2021-07-15 (Git) OS:
Private report: No CVE-ID: None
 [2021-07-15 21:32 UTC] mail at gh01 dot de
Description:
------------
PHP 8.0 (correct): https://3v4l.org/Wofuu#v8.0.8
PHP 8.1 (wrong): https://3v4l.org/Wofuu/rfc#vgit.master

Test script:
---------------
<?php

$dt1 = new DateTimeImmutable('2020-07-19 18:30:00', new DateTimeZone('Europe/Berlin'));
$dt2 = new DateTimeImmutable('2020-07-19 16:30:00', new DateTimeZone('UTC'));

print_r($dt1->diff($dt2));

Expected result:
----------------
DateInterval Object
(
    [y] => 0
    [m] => 0
    [d] => 0
    [h] => 0
    [i] => 0
    [s] => 0
    [f] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 0
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

Actual result:
--------------
DateInterval Object
(
    [y] => -1
    [m] => 11
    [d] => 29
    [h] => 24
    [i] => 0
    [s] => 0
    [f] => 0
    [weekday] => 0
    [weekday_behavior] => 0
    [first_last_day_of] => 0
    [invert] => 0
    [days] => 0
    [special_type] => 0
    [special_amount] => 0
    [have_weekday_relative] => 0
    [have_special_relative] => 0
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-08-08 11:18 UTC] derick@php.net
-Status: Open +Status: Duplicate
 [2021-08-08 11:18 UTC] derick@php.net
Duplicate of #81273
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Mon Sep 20 21:03:37 2021 UTC