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

 ID:                 48187
 Comment by:         jasonjoo dot god at gmail dot com
 Reported by:        wavetrex at gmail dot com
 Summary:            DateTime::diff() corrupting microtime() result
 Status:             Open
 Type:               Bug
 Package:            Date/time related
 Operating System:   Windows 2003 Server
 PHP Version:        5.3.0RC2
 Block user comment: N

 New Comment:

my test script below:

<?php 

date_default_timezone_set("Asia/Chongqing");

echo microtime(true);

echo "\n";

$now=new DateTime();

$now->diff(new DateTime());

echo microtime(true);

?>

and my os is win32/xp

I found this isue can be reproduced under apache in handler mode, but it
is no isue in command line mode(eg. php test.php).



for example, I got its output like this:

1281415176.9756

1281402595.446

and the wrong one only change the part following dot



my php version is 5.3.3


Previous Comments:
------------------------------------------------------------------------
[2010-07-18 00:47:15] k.schroe...@php.net

Automatic comment from SVN on behalf of k.schroeder
Revision: http://svn.php.net/viewvc/?view=revision&amp;revision=301359
Log: Test for #48187

------------------------------------------------------------------------
[2009-05-10 01:41:59] wavetrex at gmail dot com

float(1241919300.3593)

float(1241709350.3736)

int(1241919300)

int(1241919300)

string(25) "2009-05-10T04:35:00+03:00"

string(25) "2009-05-10T04:35:00+03:00"



( http://wt.ath.cx/jani.php )



Note: 1241709350 -> this value seems to stay almost unchanged over time


(look at my first submission: string(21) "0.25882200 1241709345" )



When I reported the difference was ~50000 seconds, now it's over 200.000

------------------------------------------------------------------------
[2009-05-09 20:59:00] j...@php.net

What is the output of the script I provided?

------------------------------------------------------------------------
[2009-05-09 06:58:21] wavetrex at gmail dot com

@jani:



I'm using microtime() multiple times to determine how long some 

complex parts of the script take to execute, when I noticed weird 

differences.



Also, while the second microtime() call after diff() is wrong, the 

third seems to be ok, just like calling the function resets some 

internal variable that was broken during execution of diff()



I prepared a script on my server:

http://wt.ath.cx/diff.php

The code for this script is here:

http://wt.ath.cx/diff.txt



Server configuration:

http://wt.ath.cx/phpinfo.php



Time difference between the two calls:



Expected result:

3.814697265625E-5 (a few microseconds)

Actual result:

-142455.45035195 (??)



Your script:

http://wt.ath.cx/jani.php

... also has the error.



If this probably occurs on my server, I'm thinking... it might be 

timezone related ? I'm sure yours and mine are different. (check my 

phpinfo.php to see date/time settings)



P.S.

While investigating, I noticed that in some rare cases it doesn't 

happen, and after Ctrl-R it gives the erroned value again. Try 

reloading the page a few times in case 1st time it shows the correct 

values.



I'll keep experimenting with the new 5.3.0 time functions and see if 

some other errors appear.

------------------------------------------------------------------------
[2009-05-09 04:15:40] j...@php.net

Try this script instead: (I can't reproduce this..)



<?php

// two arbitrary dates

$date1=new DateTime("2005-07-23");

$date2=new DateTime("2006-02-14");



$begin_u = microtime(true);

$begin_t = time();

$begin_a = date(DATE_ATOM);



var_dump($date1->diff($date2));



var_dump($begin_u, microtime(true));

var_dump($begin_t, time());

var_dump($begin_a, date(DATE_ATOM));

?>



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


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=48187


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

Reply via email to