1
0
mirror of https://github.com/dg/dibi.git synced 2025-08-06 14:16:39 +02:00

Result, Row: added support for datetime like 'Jun 17 2015 12:00:00:000AM' [Closes #180]

This commit is contained in:
David Grudl
2016-09-02 17:36:37 +02:00
parent be7c3f095d
commit 74d0a78ec2
2 changed files with 2 additions and 2 deletions

View File

@@ -515,7 +515,7 @@ class Result implements IDataSource
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
} elseif ($type === Type::DATETIME || $type === Type::DATE || $type === Type::TIME) {
if ((int) $value !== 0 || substr((string) $value, 0, 3) === '00:') { // '', NULL, FALSE, '0000-00-00', ...
if ($value && substr((string) $value, 0, 3) !== '000') { // '', NULL, FALSE, '0000-00-00', ...
$value = new DateTime($value);
$row[$key] = empty($this->formats[$type]) ? $value : $value->format($this->formats[$type]);
} else {

View File

@@ -38,7 +38,7 @@ class Row implements \ArrayAccess, \IteratorAggregate, \Countable
{
$time = $this[$key];
if (!$time instanceof DateTime) {
if ((int) $time === 0 && substr((string) $time, 0, 3) !== '00:') { // '', NULL, FALSE, '0000-00-00', ...
if (!$time || substr((string) $time, 0, 3) === '000') { // '', NULL, FALSE, '0000-00-00', ...
return NULL;
}
$time = new DateTime($time);