mirror of
https://github.com/dg/dibi.git
synced 2025-08-03 20:57:36 +02:00
differentiated Type::TIME and Type::DATETIME
This commit is contained in:
@@ -515,7 +515,7 @@ class Result implements IDataSource
|
||||
} elseif ($type === Type::BOOL) {
|
||||
$row[$key] = ((bool) $value) && $value !== 'f' && $value !== 'F';
|
||||
|
||||
} elseif ($type === Type::DATE || $type === Type::DATETIME) {
|
||||
} 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', ...
|
||||
$value = new DateTime($value);
|
||||
$row[$key] = empty($this->formats[$type]) ? $value : $value->format($this->formats[$type]);
|
||||
|
@@ -20,7 +20,7 @@ class Type
|
||||
INTEGER = 'i',
|
||||
FLOAT = 'f',
|
||||
DATE = 'd',
|
||||
DATETIME = 't',
|
||||
DATETIME = 'dt',
|
||||
TIME = 't',
|
||||
TIME_INTERVAL = 'ti';
|
||||
|
||||
|
@@ -192,3 +192,36 @@ test(function () {
|
||||
Assert::equal(['col' => '2015-10-13 00:00:00'], $result->test(['col' => '2015-10-13']));
|
||||
Assert::equal(['col' => '2015-10-13 14:30:00'], $result->test(['col' => '2015-10-13 14:30']));
|
||||
});
|
||||
|
||||
|
||||
test(function () {
|
||||
$result = new MockResult;
|
||||
$result->setType('col', Type::DATE);
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
||||
Assert::exception(function () use ($result) {
|
||||
$result->test(['col' => TRUE]);
|
||||
}, 'Exception');
|
||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00']));
|
||||
Assert::equal(['col' => new Dibi\DateTime('2015-10-13')], $result->test(['col' => '2015-10-13']));
|
||||
});
|
||||
|
||||
|
||||
test(function () {
|
||||
$result = new MockResult;
|
||||
$result->setType('col', Type::TIME);
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => NULL]));
|
||||
Assert::exception(function () use ($result) {
|
||||
$result->test(['col' => TRUE]);
|
||||
}, 'Exception');
|
||||
Assert::same(['col' => NULL], $result->test(['col' => FALSE]));
|
||||
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '']));
|
||||
Assert::same(['col' => NULL], $result->test(['col' => '0000-00-00']));
|
||||
Assert::equal(['col' => new Dibi\DateTime('00:00:00')], $result->test(['col' => '00:00:00']));
|
||||
Assert::equal(['col' => new Dibi\DateTime('14:30')], $result->test(['col' => '14:30']));
|
||||
});
|
||||
|
Reference in New Issue
Block a user