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

DateRange filter: Yesterday option fails on January 1st #849

Closed
marcgibbons opened this issue Jan 1, 2018 · 0 comments · Fixed by #852
Closed

DateRange filter: Yesterday option fails on January 1st #849

marcgibbons opened this issue Jan 1, 2018 · 0 comments · Fixed by #852

Comments

@marcgibbons
Copy link

marcgibbons commented Jan 1, 2018

Happy new year!

Running my test suite this morning revealed that the "yesterday" option of the DateRangeFilter fails on January 1.

This happens because today's year is extracted rather than yesterday's year to generate the queryset filter parameter. Given that today is Jan 1, 2018, the date of Dec 31, 2018 is used rather than Dec 31, 2017.

5: (_('Yesterday'), lambda qs, name: qs.filter(**{
'%s__year' % name: now().year,
'%s__month' % name: now().month,
'%s__day' % name: (now() - timedelta(days=1)).day,

Generated SQL:
WHERE (my_date_field BETWEEN 2018-01-01 AND 2018-12-31 AND EXTRACT(MONTH FROM my_date_field) = 1 AND EXTRACT(DAY FROM my_date_field) = 31)'

This appears to fix:

     '%s__year' % name: (now() - timedelta(days=1)).year, 
     '%s__month' % name: (now() - timedelta(days=1)).month,
     '%s__day' % name: (now() - timedelta(days=1)).day, 

PR to follow.

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 a pull request may close this issue.

1 participant