php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #66545 DateTime
Submitted: 2014-01-22 14:13 UTC Modified: 2021-04-06 19:52 UTC
Votes:4
Avg. Score:4.0 ± 1.7
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: perrier dot p at gmail dot com Assigned: derick (profile)
Status: Closed Package: Date/time related
PHP Version: 5.5.8 OS: Debian 7
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: perrier dot p at gmail dot com
New email:
PHP Version: OS:

 

 [2014-01-22 14:13 UTC] perrier dot p at gmail dot com
Description:
------------
DateInterval fail to calculate number of days and hours

http://3v4l.org/ab0Hm#v5424

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

$debut = mktime(0, 0, 0, 10, 27, 2013);
$fin = mktime(23, 59, 59, 11, 10, 2013);

$d1 = new DateTime('now',new DateTimeZone('Europe/Paris'));
$d2 = new DateTime('now',new DateTimeZone('Europe/Paris'));
$d1->setTimestamp($debut);
$d2->setTimestamp($fin);
$diff = $d1->diff($d2);

print_r($diff);

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

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

Patches

interval.c (last revision 2014-01-25 21:41 UTC by perrier dot p at gmail dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-01-24 21:33 UTC] s dot wuerker at injc dot net
I've got the same problem with the following code:

http://3v4l.org/ekMU7
 [2016-06-20 15:57 UTC] cmb@php.net
> DateInterval fail to calculate number of days and hours

Well, actually it does calculate the number of days and hours (14
days + 23 hours == 15 days - 1 hour), but obviously the values
don't get normalized. Not sure if that's a bug or something to be
documented.
 [2021-04-06 19:52 UTC] derick@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: derick
 [2021-04-06 19:52 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: Thu Nov 21 10:01:29 2024 UTC