Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateTimeRangeFilter upper time bound includes microseconds #115

Merged
merged 1 commit into from
Feb 17, 2024

Conversation

ef-end-y
Copy link
Contributor

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 silentsokolov merged commit 979e87b into silentsokolov:master Feb 17, 2024
33 checks passed
@silentsokolov
Copy link
Owner

Thx

@ShudelEV
Copy link

ShudelEV commented Apr 4, 2024

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
Copy link

ShudelEV commented Apr 4, 2024

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
Copy link

@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
Copy link
Owner

silentsokolov commented Apr 11, 2024

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

@yungchin
Copy link

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
Copy link
Owner

Microseconds are optional. Use RANGEFILTERS_USE_FILTER_END_MICROSECOND, default False

@yungchin
Copy link

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

@silentsokolov
Copy link
Owner

Fix >_<

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants