Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ErrorException: Call to a member function format() on boolean /AvaTax/GetTaxRequest.php [ 44 ] #30

Open
shiloanton opened this issue Aug 19, 2016 · 6 comments

Comments

@shiloanton
Copy link

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 ]

@shiloanton shiloanton changed the title ErrorException [ 1 ]: Call to a member function format() on boolean /AvaTax/GetTaxRequest.php [ 44 ] ErrorException: Call to a member function format() on boolean /AvaTax/GetTaxRequest.php [ 44 ] Aug 19, 2016
@skylord123
Copy link
Contributor

I cannot reproduce this issue. What PHP version are you running? Need more information to test.

@skylord123
Copy link
Contributor

skylord123 commented Sep 1, 2016

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.

@estevejm
Copy link
Contributor

estevejm commented Sep 2, 2016

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.

@estevejm
Copy link
Contributor

estevejm commented Sep 2, 2016

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

@TkachukRuslan
Copy link

Hi
Could you please update the status of this issue
Waiting your response.

@estevejm
Copy link
Contributor

estevejm commented Sep 7, 2016

@TkachukRuslan the issue was reproduced and a PR that fixes it was opened (#35). We're now waiting it to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants