concrete-datastore
concrete-datastore copied to clipboard
Fix date and datetime filters
Description of the problem
Concrete range / comparaison filters use a method convert_type that takes an argument close_period (defaults to True):
For DateTime fields, if close_period is true, we consider the end of the day, otherwise we consider the start of the day.
Example:
convert_type("2022-02-24T15:50:00Z", "DateTimeField", close_period=True) # 2022-02-24T00:00:00Z
convert_type("2022-02-24T15:50:00Z", "DateTimeField", close_period=False) # 2022-02-24T23:59:59Z
If we have a model MyModel with field datetime, and two instances of this model:
- instance1:
datetime = 2022-02-24T18:45:12.1653Z - instance2:
datetime = 2022-02-24T20:02:33.233Z
If we apply the API filter: ?datetime__range=2022-02-24T19:00:00Z,2022-02-24T22:00:00Z, we expect to get the instance 2 in the results of the request, but we have both results, because what is actually done is a datetime__range=2022-02-24T00:00:00Z,2022-02-24T23:59:59Z
Fix
⚠️ This issue should be handeled first https://github.com/Netsach/concrete-datastore/issues/124
Supported formats for DateTime filters
YYYY-MM-DD: (regex:r'^\d{4}-\d{2}-\d{2}$')YYYY-MM-DDTHH:mm:ssZ: (regex:r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$')YYYY-MM-DDTHH:mm:ss.xxxxxxZ: (regex:r'^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d{1,6})?Z$')
Possible filters
Comparaison filters
| lookup \ date format | YYYY-MM-DD |
YYYY-MM-DDTHH:mm:ssZ |
YYYY-MM-DDTHH:mm:ss.xxxxxxZ |
|---|---|---|---|
__gte |
dt.start_of('day') |
dt.start_of('second') |
dt |
__gt |
dt.end_of('day') |
dt.end_of('second') |
dt |
__lte |
dt.end_of('day') |
dt.end_of('second') |
dt |
__lt |
dt.start_of('day') |
dt.start_of('second') |
dt |
Range filters
For the range filter: __range=datetime_min,datetime_max:
| value \ date format | YYYY-MM-DD |
YYYY-MM-DDTHH:mm:ssZ |
YYYY-MM-DDTHH:mm:ss.xxxxxxZ |
|---|---|---|---|
datetime_min |
dt.start_of('day') |
dt.start_of('second') |
dt |
datetime_max |
dt.end_of('day') |
dt.end_of('second') |
dt |