Improve determination of "end" in db constraints

Some dates might not have an end date, but only start.
Those should be respected.
This commit is contained in:
Daniel Siepmann 2021-09-07 15:58:10 +02:00
parent 26cc0d3f8c
commit da87dc7644

View file

@ -65,7 +65,18 @@ class DateRepository extends Repository
$constraints['starts'] = $query->greaterThanOrEqual('start', $demand->getStart()); $constraints['starts'] = $query->greaterThanOrEqual('start', $demand->getStart());
} }
if ($demand->getEnd() != null) { if ($demand->getEnd() != null) {
$constraints['ends'] = $query->lessThanOrEqual('end', $demand->getEnd()); // Dates might have end of 0 if only start exists.
// This is respected to take start as end date.
$constraints['ends'] = $query->logicalOr([
$query->logicalAnd([
$query->lessThanOrEqual('end', $demand->getEnd()),
$query->greaterThan('end', 0)
]),
$query->logicalAnd([
$query->equals('end', 0),
$query->lessThanOrEqual('start', $demand->getEnd())
]),
]);
} }
if ($demand->getStart() === null && $demand->getEnd() === null) { if ($demand->getStart() === null && $demand->getEnd() === null) {