Skip to content

Commit

Permalink
Add DateInterval type parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
ossinkine committed Sep 28, 2017
1 parent 53245e8 commit 4fdbdab
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"php": "^7.1",
"ext-pdo": "*",
"doctrine/collections": "^1.4",
"doctrine/dbal": ">=2.5-dev,<2.7-dev",
"doctrine/dbal": "^2.6",
"doctrine/instantiator": "~1.1",
"doctrine/common": "^2.7.1",
"doctrine/cache": "~1.6",
Expand Down
4 changes: 4 additions & 0 deletions lib/Doctrine/ORM/Query/ParameterTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ public static function inferType($value)
return Type::DATETIME;
}

if ($value instanceof \DateInterval) {
return Type::DATEINTERVAL;
}

if (is_array($value)) {
return is_int(current($value))
? Connection::PARAM_INT_ARRAY
Expand Down
5 changes: 3 additions & 2 deletions tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ class ParameterTypeInfererTest extends OrmTestCase

public function providerParameterTypeInferer()
{
$data = [
$data = [
[1, Type::INTEGER],
["bar", PDO::PARAM_STR],
["1", PDO::PARAM_STR],
[new \DateTime, Type::DATETIME],
[new \DateInterval('P1D'), Type::DATEINTERVAL],
[[2], Connection::PARAM_INT_ARRAY],
[["foo"], Connection::PARAM_STR_ARRAY],
[["1","2"], Connection::PARAM_STR_ARRAY],
[[], Connection::PARAM_STR_ARRAY],
[true, Type::BOOLEAN],
];
];

if (PHP_VERSION_ID >= 50500) {
$data[] = [new \DateTimeImmutable(), Type::DATETIME];
Expand Down

0 comments on commit 4fdbdab

Please sign in to comment.