AntonTerekhov / OrientDB-PHP

Binary protocol for OrientDB for PHP applications (Beta)
http://code.google.com/p/orient/wiki/NetworkBinaryProtocol
BSD 3-Clause "New" or "Revised" License
108 stars 23 forks source link

Two Problems with DateTime conversion #13

Closed crashtech closed 5 years ago

crashtech commented 12 years ago

First, on line 131 and 132 of the file "OrientDBDataTypes.php" we have a conversion to INT of the value of the date. This conversion makes a rounding and changes the date, and can be broken by PHP_INT_MAX definition. Apparently change INT to FLOAT with a rounding operation solve this problem, but.

Second, the date and time received from the socket is completly wrong. In the Studio of OrientDB, the field "registration" shows the correct date "2012-05-27 04:51:00:000" but, when the socket received the date in the number format, it's "1338105246000t" that represent "1909-01-05 23:34:20". I don't know if it's a socket issue or OrientDB issue, but is critical issue. Maybe the correct way, is convert the date string direct on php.

AntonTerekhov commented 12 years ago

Thanks for the report, I'll look into it.

crashtech commented 12 years ago

With more information, I found what really happened.

The format that comes from the OrientDB has the milliseconds included, that turns the value in a millisecond date format. The PHP time function, and other date operations, work with seconds date format.

Example: Orient format for "21/03/2010 00:00:00" is 1269140400000t PHP format for "21/03/2010 00:00:00" is 1269140400

So, the solution is simple remove the "t" string from the end of the value, this the class already do, and get the value as float and divide it by 1000.

In the example above, the value "1269140400000t" will turn to "1269140400.000". Milliseconds in PHP is represented by float values.

dam2k commented 11 years ago

I solved the "wrong date" problem this way: new OrientDBTypeDate(time() . "000t");

Manutd2014 commented 10 years ago

I can't load property datetime. I wish receive example for this problem. When I debug, I try copy data of field datetime : '1407708018000t'. After I do recordCreate $record->data->ngayt = new OrientDBTypeDate('1407708018000t') but error.