Custom Date Filter


say i have an entity Foo with bar as a LocalDateTime property.

I have a browse screen for Foo which I need to provide a custom week filter. i need to match all records that match the given week.

cuba provides this by doing the following:

however this requires the user to provide 2 dates. I need a solution where the user inputs one date, lets say 2019-09-16, and the query/code will figure out somehow what the first day of the week is and the last day of the week and do a between query.

I tried to implement this with Macros in JPQL - CUBA Platform. Developer’s Manual
the @between macro looks promising but the time_unit only works in relation with “now” and not with a given parameter.

I then tried to create my own jpql macro, however this is not possible because there are hardcoded references to the default jpql macros provided by cuba-platform
at: cuba/ at master · cuba-platform/cuba · GitHub and cuba/JPA2.g at master · cuba-platform/cuba · GitHub

any ideas how to make this work?


I’m afraid in generic filter you can implement it only using a database function by invoking it via FUNCTION JPQL keyword. Something like function('COMPAREWEEK', {E}.bar, ?) = 1

But you can also easily create a custom filter using query conditions, where you have full control over JPQL and parameter values.