-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
While trying to rewrite some filtering functionality with Specifications, I think I encountered a limitation when trying to determine whether an Entity is 'valid' at a specific DateTime.
The Entity has two properties of type DateTime:
- validFrom: DateTime when Entity becomes valid
- validTo: DateTime when Entity is no longer valid
Using the ExpressionBuilder:
$expressionBuilder->between(':specificDateParameter', 'x.validFrom', 'x.validTo');Using Specifications:
new Specification([
new Between($entityPropertyName, $fromParameter, $toParameter),
]);So
- the ExpressionBuilder checks whether a specific date is between a range defined by Entity properties
- one parameter used
- two Entity properties involved
- the Specification checks whether a specific Entity property is between a certain range
- two parameters used
- one Entity property involved
One could use:
new Specification([
new GreaterThanOrEquals('validFrom', $specificDate),
new LessThanOrEquals('validTo', $specificDate),
]);But I kind of 'prefer' the elegance of Between...
Any idea / pointers on how to deal with this scenario?
Additionally
And what if the year should not be taken into account? We used DayOfYear() with the ExpressionBuilder:
$expressionBuilder->between(
'DayOfYear(:specificDateParameter)',
'DayOfYear(x.validFrom)',
'DayOfYear(x.validTo)'
);Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels