python - How to test datetime conversion with pytz and tzlocal? -



python - How to test datetime conversion with pytz and tzlocal? -

so have datetime objects want show users in local time.

using answered questions on here, i've come jinja filter accomplish this:

from tzlocal import get_localzone import pytz def local_datetime(utc_dt): local_tz = get_localzone() local_dt = utc_dt.replace(tzinfo=pytz.utc).astimezone(local_tz) homecoming local_dt.strftime('%m/%d/%y @ %i:%m %p') app.jinja_env.filters['local_dt'] = local_datetime {{ user.last_login_at|local_dt }} # in template

my thought run each time views page (hence filter) show in user's native timezone.

it shows right on development machine, i'd create sure get_localzone() grabbing user's local timezone , not server's.

my question is: how can test if working correctly?

get_localzone() homecoming local timezone of server application running on.

there nil in http headers of request can tell user's timezone. instead, standard way of approaching inquire user tell preferred timezone.

see determining web user's time zone more give-and-take this.

python datetime flask jinja2 pytz

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -