Skip to content
This repository has been archived by the owner on Jan 21, 2020. It is now read-only.

Commit

Permalink
Merge fe46565 into cca97a6
Browse files Browse the repository at this point in the history
  • Loading branch information
zluiten committed Sep 13, 2019
2 parents cca97a6 + fe46565 commit d685096
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/Filter/ORM/AbstractFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace ZF\Doctrine\QueryBuilder\Filter\ORM;

use DateTime;
use DateTimeImmutable;
use ZF\Doctrine\QueryBuilder\Filter\FilterInterface;
use ZF\Doctrine\QueryBuilder\Filter\Service\ORMFilterManager;

Expand Down Expand Up @@ -64,6 +65,16 @@ protected function typeCastField($metadata, $field, $value, $format, $doNotTypec
$value = DateTime::createFromFormat('Y-m-d H:i:s', $value->format('Y-m-d') . ' 00:00:00');
}
break;
case 'date_immutable':
// For dates set time to midnight
if ($value && ! $doNotTypecastDatetime) {
if (! $format) {
$format = 'Y-m-d';
}
$value = DateTimeImmutable::createFromFormat($format, $value);
$value = DateTimeImmutable::createFromFormat('Y-m-d H:i:s', $value->format('Y-m-d') . ' 00:00:00');
}
break;
case 'time':
if ($value && ! $doNotTypecastDatetime) {
if (! $format) {
Expand All @@ -72,6 +83,14 @@ protected function typeCastField($metadata, $field, $value, $format, $doNotTypec
$value = DateTime::createFromFormat($format, $value);
}
break;
case 'time_immutable':
if ($value && ! $doNotTypecastDatetime) {
if (! $format) {
$format = 'H:i:s';
}
$value = DateTimeImmutable::createFromFormat($format, $value);
}
break;
case 'datetime':
if ($value && ! $doNotTypecastDatetime) {
if (! $format) {
Expand All @@ -80,6 +99,14 @@ protected function typeCastField($metadata, $field, $value, $format, $doNotTypec
$value = DateTime::createFromFormat($format, $value);
}
break;
case 'datetime_immutable':
if ($value && ! $doNotTypecastDatetime) {
if (! $format) {
$format = 'Y-m-d H:i:s';
}
$value = DateTimeImmutable::createFromFormat($format, $value);
}
break;
default:
break;
}
Expand Down

0 comments on commit d685096

Please sign in to comment.