Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Support for microseconds #246
Database systems support microseconds in datetime columns, but Dibi always escaped datetime values without second fractions. Therefore even if the datetime column in database is set to accept second fractions, it would always store just full second. I changed formatting rules to include second fractions with date format u (supported since PHP 5.2.2).
If database system is not set to use second fractions, it should beignored, however I'm not sure, if other databases than MySQL, MSSQL and Postgres support time fractions, so I've changed just these drivers.
Feb 6, 2017
referenced this pull request
Mar 24, 2017
@hubipe can you give a source for this statement? I've come across this issue as it's BC BREAK in my opinion .. when the datetime column stores only full seconds, then any comparison using also fractions will fail.. Am I missing sth.?
I see what are you referring to. In my opinion this is expected behaviour. Compare it with this modified example. When you compare date time column with 0 microseconds it is automatically presumed, that microseconds are 0. Thus comparing with microsecond time with any different microseconds than 0 will result in empty result.
In this way, that PR might be considered as a BC break, if you had depended on this falsy behavior. The question is, if it should stay as it is and you should fix your code not to use microseconds, or if dibi should make a change
Yes, I agree.
$dt = new DateTime(); // https://secure.php.net/manual/en/datetime.construct.php for php >=7.1 microseconds are filled with actual value. Not with '00000'. dibi::insert(table, [date=>$dt]); // inserts record without the microseconds dibi::select(*)->from(table)->where('date=%dt', $dt); // empty result
this example and similar use cases worked prior this PR regardless the php version used. With this PR they work seamlessly with php <=7.1 only.
Correct me if I'm wrong, this affects only cases when you create
I think the easiest solution would be keep this PR, add notice to older releases and add helper function that strips microseconds from DateTime.
$stripped = dibi::stripMicroseconds(new DateTime); // or stripMicrotime?