silentsokolov / django-admin-rangefilter

A Django app that lets you filter data by date range and numeric range in the admin UI
MIT License
721 stars 106 forks source link

DateTimeRangeFilter upper time bound includes microseconds #115

Closed ef-end-y closed 9 months ago

ef-end-y commented 9 months ago

In Django admin we can input time range 00:00:00 to 23:59:59 (or another time range) into text fields. The db-query does not consider the last second, since we do not take into account microseconds: WHERE "created_at" >= '''2024-02-13 00:00:00''' AND "created_at" <= '''2024-02-13 23:59:59.999999'''

silentsokolov commented 9 months ago

Thx

ShudelEV commented 7 months ago

But now another problem:

I have record with datetime value 2024-04-01T00:00:00.362726 and use filter range 2024-03-01T00:00:00 - 2024-04-01T00:00:00 (March report) and see this record but I shouldn't :)

ShudelEV commented 7 months ago

In Django admin we can input time range 00:00:00 to 23:59:59 (or another time range) into text fields. The db-query does not consider the last second, since we do not take into account microseconds: WHERE "created_at" >= '''2024-02-13 00:00:00''' AND "created_at" <= '''2024-02-13 23:59:59.999999'''

For this case you can just use filter 00:00:00 to 00:00:00 +1day

yungchin commented 7 months ago

@silentsokolov I would concur with @ShudelEV that this change introduces odd behaviour. Would it perhaps be better to add an option to have __lt instead of __lte on the upper bound?

silentsokolov commented 7 months ago

Could the issue be with different databases, where working with microseconds is poorly supported?

yungchin commented 7 months ago

I would argue there wasn't an issue here.

If I understand correctly, what this PR sought to address, namely that if we select an upper bound of 23:59:59, this would not include, say, a later time of 23:59:59.250 -- isn't that just expected behaviour? If we did want to select that time too, we could just set the upper bound at 00:00:00 of the next day.

From that point of view, the change in this PR breaks expectations ever so slightly. Whatever end time you enter, you now always get almost an extra second on top?

silentsokolov commented 7 months ago

Microseconds are optional. Use RANGEFILTERS_USE_FILTER_END_MICROSECOND, default False

yungchin commented 7 months ago

Thank you for making this change, super 🙏 About this line: shouldn't that be without the not?

silentsokolov commented 7 months ago

Fix >_<