Skip to content

Commit 55dabf8

Browse files
committed
ensure the values match Y-m-d for date filter
1 parent 7784c16 commit 55dabf8

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Traits/WithFilters.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Rappasoft\LaravelLivewireTables\Traits;
44

5+
use DateTime;
56
use Illuminate\Database\Eloquent\Builder;
67
use Illuminate\Database\Eloquent\Relations\Relation;
78
use Rappasoft\LaravelLivewireTables\Utilities\ColumnUtilities;
@@ -150,7 +151,11 @@ public function cleanFilters(): void
150151
}
151152

152153
if ($filterDefinitions[$filterName]->isDate()) {
153-
return true;
154+
// array_sum trick is a terse way of ensuring that PHP
155+
// did not do "month shifting"
156+
// (e.g. consider that January 32 is February 1)
157+
$dt = DateTime::createFromFormat("Y-m-d", $filterValue);
158+
return $dt !== false && !array_sum($dt::getLastErrors());
154159
}
155160

156161
return false;

0 commit comments

Comments
 (0)