From:             urkle at outoforder dot cc
Operating system: CentOS 5
PHP version:      5.3.0
PHP Bug Type:     Feature/Change Request
Bug description:  Add support for microtime to DateTime object construction

Description:
------------
Currently the DateTime object construction accepts a strtotime type input
only for setting the date on the object.  This means that when trying to
get the current time WITH microseconds you have to do something like
this..

<?php
$t = microtime(true);
$micro = sprintf("%06d",($t - floor($t)) * 1000000);
$d = new DateTime( date('Y-m-d H:i:s.'.$micro,$t) );
?>

which is highly inefficient as we are converting a float into a string and
then converting it from a string into the internal format for the DateTime
object.

It would be really nice to have a constructor for the DateTime object that
would accept a float argument (defaulting to NOW w/ microseconds)

Possible suggestions would be
factory method
$d = DateTime::TimeWithMicroseconds();

make the constructor accept a float
$d = new DateTime(microtime(true));

modify the setTimestamp method in PHP 5.3 to accept a float.
$d = new DateTime();
$d->setTimestamp(microtime(true));


-- 
Edit bug report at http://bugs.php.net/?id=49779&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49779&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49779&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49779&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49779&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49779&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49779&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49779&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49779&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49779&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49779&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49779&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49779&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49779&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49779&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49779&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49779&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49779&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49779&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49779&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49779&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49779&r=mysqlcfg

Reply via email to