Open shiloanton opened 8 years ago
I cannot reproduce this issue. What PHP version are you running? Need more information to test.
Does changing
$date = \DateTime::createFromFormat('U.u', microtime(true));
to
$date = new \DateTime();
Fix the issue?
I don't know why the code is using microtime. The DocDate is a date not date and time. Creating a new \DateTime
object without a parameter will create it off the current time anyways. Even if we were using the time of day as well we wouldn't need to use microtime.. No point in that much accuracy.
We're having the same issue with PHP 5.6.5, we were not able to reproduce it so far.
About using that much accuracy, the microtime information is not used in DocDate
but it's being used in DocCode
.
public function __construct()
{
$date = \DateTime::createFromFormat('U.u', microtime(true));
$this->DocDate = $date->format('Y-m-d');
...
$this->DocCode = $date->format('Y-m-d-H-i-s.u');
}
I don't know why a DateTime is being used to identify the DocCode by default, maybe generating a unique id would be enough and would allow us to generate the DateTime without the microtime as @skylord123 suggested.
Finally we were able to reproduce it. Extracted from http://php.net/manual/en/datetime.createfromformat.php
Reportedly, microtime() may return a timestamp number without a fractional part if the microseconds are exactly zero. I.e., "1463772747" instead of the expected "1463772747.000000". number_format() can create a correct string representation of the microsecond timestamp every time, which can be useful for creating DateTime objects when used with DateTime::createFromFormat():
<?php
$now = DateTime::createFromFormat('U.u', number_format(microtime(true), 6, '.', ''));
var_dump($now->format('Y-m-d H:i:s.u')); // E.g., string(26) "2016-05-20 19:36:26.900794"
We will create a PR just now
Hi Could you please update the status of this issue Waiting your response.
@TkachukRuslan the issue was reproduced and a PR that fixes it was opened (#35). We're now waiting it to be merged.
DateTime returns boolean "$date = \DateTime::createFromFormat('U.u', microtime(true));" , no object, since can not convert the input parameters to DateTime object.
ErrorException [ 1 ]: Call to a member function format() on boolean /AvaTax/GetTaxRequest.php [ 44 ]