Bug #60960 [Nab]: Wrong number of days.
| From: | robertosuursoo at yahoo dot com dot br | Date: | Fri, 03 Feb 2012 13:43:32 +0000 |
| Subject: | Bug #60960 [Nab]: Wrong number of days. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-167105@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=60960&edit=1
ID: 60960
User updated by: robertosuursoo at yahoo dot com dot br
Reported by: robertosuursoo at yahoo dot com dot br
Summary: Wrong number of days.
Status: Not a bug
Type: Bug
Package: Date/time related
Operating System: Ubuntu 11.04 64bits
PHP Version: Irrelevant
Block user comment: N
Private report: N
New Comment:
Thanks a lot!
Previous Comments:
------------------------------------------------------------------------
[2012-02-03 00:50:52] aharvey@php.net
Yep, this happens with the Brazil/East time zone, so it's just crossing a DST
boundary: if you look at $interval->h on the last interval, it's 23 hours from
midnight on the 21st to midnight on the 22nd and therefore not a full day.
------------------------------------------------------------------------
[2012-02-02 22:04:47] rasmus@php.net
Unable to reproduce here as well with PHP 5.3.10. Which timezone are you using?
Most likely DST-related.
------------------------------------------------------------------------
[2012-02-02 21:42:58] anon at anon dot anon
Obviously some wretched daylight savings issue. Call:
date_default_timezone_set('UTC');
It's the only way to make any programming language's date handling sane.
------------------------------------------------------------------------
[2012-02-02 20:15:53] carloschilazo at gmail dot com
I couldnt reproduce the problem, I get a result of 1 on:
$a = new DateTime('2012-10-21');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
Tested Ubuntu 11 64 bits also
------------------------------------------------------------------------
[2012-02-02 19:48:53] robertosuursoo at yahoo dot com dot br
Description:
------------
The diff function is calculating the wrong number of days.
PHP 5.3.5-1ubuntu7.4 with Suhosin-Patch (cli) (built: Dec 13 2011 18:30:11)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.1.0, Copyright (c) 2002-2010, by Derick Rethans
Test script:
---------------
<html><head><title>TEST</title></head><body>
<?php
$a = new DateTime('2012-10-19');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
?>
<p>$interval->days:<?=$interval->days?></p>
<?php
$a = new DateTime('2012-10-20');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
?>
<p>$interval->days:<?=$interval->days?></p>
<?php
$a = new DateTime('2012-10-21');
$b = new DateTime('2012-10-22');
$interval = $a->diff($b);
?>
<p>$interval->days:<?=$interval->days?></p>
</body></html>
Expected result:
----------------
$interval->days:3
$interval->days:2
$interval->days:1
Actual result:
--------------
$interval->days:3
$interval->days:2
$interval->days:0
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=60960&edit=1