slashmili / django-jalali

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

How to set timezone to the jdateTimeField - not the machine time #52

Closed masoudian closed 6 years ago

masoudian commented 7 years ago

django 1.10 and python 2.7 If I define my model field like this:

    class Book(models.Model):
        objects = jmodels.jManager()
        jdate = jmodels.jDateTimeField(auto_now_add=True)

when a new Book instance is created with book = Book.objects.create(), jdate 's value will be my local machine time (my laptop)! And I need the time be equal the timezone. I need to calculate the elapsed time. But because of the local time, the elapsed time would be a minus number!!

    utcnow = jdatetime.datetime.utcnow().replace(tzinfo=utc)
    bookDate = book.jdate
    elapsedTime = utcnow - bookDate 

I also have the USE_TZ = True in the settings.py Am I doing something wrong? Or django-jalali does not support timezone aware type?

Thanks in advance

slashmili commented 7 years ago

Hey @masoudian,

I tried it and it didn't work for me as well. not sure where to make the changes though.

Let's see if we can fix it, do you have any suggestion?

slashmili commented 6 years ago

I've added support for timezone in master and also dropped support for Django 1.X.

If you need to use timezone please consider upgrading to Django 2.0 and use version 3 of Django jalali