slashmili / django-jalali

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

Fix datetime parsing problem in ``JDateTimeField`` #201

Closed hramezani closed 1 year ago

hramezani commented 1 year ago

Fixes https://github.com/slashmili/django-jalali/issues/193

slashmili commented 1 year ago

Could you please add a test? Wondering what's the diff between 1401-6-30 00:00 and 1401-6-31 00:00

hramezani commented 1 year ago

Could you please add a test?

I already added some tests to prove the fix. Do you have any special test cases in your mind?

Wondering what's the diff between 1401-6-30 00:00 and 1401-6-31 00:00

@slashmili I think the current implementation was wrong. The serializers/serializerfield.JDateTimeField.to_python does not handle string values and it passes the string value to jDateTimeField.parse_date. parse_data tries to parse string value by time.strptime. time.strptime parses the date as gregorian datetime. So, 1401-6-31 is not a valid date because June has 30 days.

https://github.com/slashmili/django-jalali/blob/2f13a1cd4ab315978339262046e3fea6ed6a69d0/django_jalali/db/models.py#L272-L330

slashmili commented 1 year ago

Thanks!