Bug #52480 [Opn->Asn]: Incorrect difference using DateInterval

From: Date: Fri, 30 Jul 2010 08:46:56 +0000
Subject: Bug #52480 [Opn->Asn]: Incorrect difference using DateInterval
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-152970@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=52480&edit=1

 ID:                 52480
 Updated by:         derick@php.net
 Reported by:        alex dot joyce at staff dot comcen dot com dot au
 Summary:            Incorrect difference using DateInterval
-Status:             Open
+Status:             Assigned
 Type:               Bug
 Package:            Date/time related
 Operating System:   Debian 5.0.3
 PHP Version:        5.3.3
-Assigned To:        
+Assigned To:        derick
 Block user comment: N

 New Comment:

This is going to be a fun one to fix :-/


Previous Comments:
------------------------------------------------------------------------
[2010-07-30 01:40:02] alex dot joyce at staff dot comcen dot com dot au

Changing the timezone shows a difference.

Australia/Sydney (default): 5 months
UTC: 4 months 28 days

------------------------------------------------------------------------
[2010-07-29 09:35:01] degeberg@php.net

With the timezone set to Europe/Copenhagen, I get the same results as
submitter. When set to UTC, I get the same results on Rasmus. This is on
Ubuntu 10.04.

daniel@daniel-laptop:~$ php -v
PHP 5.3.4-dev (cli) (built: Jul 29 2010 09:30:24) 
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies

------------------------------------------------------------------------
[2010-07-29 09:15:41] rasmus@php.net

I don't see why I can't reproduce it then.  Try adding a call to 
date_default_timezone_set() to the top of your script and work in UTC to

eliminate local timezone issues.  

  date_default_timezone_set('UTC');
  $date_start = new DateTime('2010-03-01');
  $date_end   = new DateTime('2010-07-29');
  $interval = $date_start->diff($date_end);
  print_r($interval);

------------------------------------------------------------------------
[2010-07-29 08:52:20] alex dot joyce at staff dot comcen dot com dot au

28/29, it doesn't matter. I'm only interested in the months.

I've tried:

1) FreeBSD 6, PHP 5.3.2
2) Debian 4, PHP 5.3.2
3) Debian 6, PHP 5.3.2/PHP 5.3.3

I upgraded that last one to submit this bug report, same fault.

All compiled from source.

------------------------------------------------------------------------
[2010-07-29 08:27:50] rasmus@php.net

Don't you mean 4 months and 28 days in the expected results?  7-3=4,
29-1=28
And that is exactly what I get on my Debian box with PHP 5.3.3:


php >   $date_start = new DateTime('2010-03-01');
php >   $date_end   = new DateTime('2010-07-29');
php > 
php >   $interval = $date_start->diff($date_end);
php > 
php >   print_r($interval);
DateInterval Object
(
    [y] => 0
    [m] => 4
    [d] => 28
    [h] => 0
    [i] => 0
    [s] => 0
    [invert] => 0
    [days] => 150
)

Are you using 5.3.3 built from our sources or are you using a
Debian-packaged 
version?

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    http://bugs.php.net/bug.php?id=52480


-- 
Edit this bug report at http://bugs.php.net/bug.php?id=52480&edit=1


Thread (28 messages)

« previous php.bugs (#152970) next »