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: 2016-06-20 15:57 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:
Status: Open Package: Date/time related
PHP Version: 5.5.8 OS: Debian 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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)

Add a Patch

Pull Requests

Add a Pull Request

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.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Nov 12 10:01:35 2019 UTC