slashmili / django-jalali

Jalali DateField support for Django model
http://pypi.python.org/pypi/django_jalali
BSD 3-Clause "New" or "Revised" License
258 stars 52 forks source link

django-jalali returned years in jalali but month and day in gregorian #142

Closed tavallaie closed 3 years ago

tavallaie commented 3 years ago

I have this query:

<jQuerySet [<SampleDate: test (1400-05-03 test ) >]>

when I filter by month=5, I get:

>> SampleDate.objects.filter(date__month=5)
<jQuerySet []>

but in the case of converting to the Gregorian, I get the result as follows:

>>> FoodDate.objects.filter(date__month=7)
<jQuerySet [<SampleDate: test (1400-05-03 test ) >

this bug only appears on month and day, not year:

>>> FoodDate.objects.filter(date__year=1400)
<jQuerySet [<SampleDate: test (1400-05-03 test ) >]>
hramezani commented 3 years ago

Thanks for reporting @tavallaie.

Django Jalali just supports __year filter. Behind the scene, it converts __year filter to __gte and __lte filter. Because it stores date and datetime in the gregorian format in the database. So, by filter(date__year=1400) Django Jalali converts it to {'date__gte': jdatetime.datetime(1400, 1, 1, 0, 0), 'date__lte': jdatetime.datetime(1400, 12, 29, 23, 59, 59)}

But, for __month and __day and other date-related filters, we cannot do this conversion.

We can add a note to the readme file and inform users about this.

slashmili commented 3 years ago

closed due to inactivity