I'm using TestCase.client to test my views. And when I call timezone.now()
from test case, i get 2015-11-17 07:48:26.826661+00:00, but when I call
start = timezone.make_aware(datetime.strptime(
date_text + ' ' + time,
'%y/%m/%d %H:%M'
))
from view I get 2015-11-17 07:36:00+02:00.
How to make them use the same timezone?
I'm running using ./manage.py test --settings=www.tests_settings
and www/tests_settings.py
contains following:
from .settings import *
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
}
}
USE_TZ = True
TIME_ZONE = 'Europe/Kiev'
>>> django.__version__
'1.8.4'
>>> pytz.__version__
'2015.7'
>>> sys.version
'3.4.3 (default, Mar 26 2015, 22:03:40) \n[GCC 4.9.2]'
Oh, I see. make_aware
returns time in default time zone, and now
- in UTC. And to get local current time, I need to do timezone.localtime(timezone.now())
.
But documentation recommends to deal with time and timezones like with text and encodings - store everything in UTC (unicode) and convert only when receiving or giving it to user.