So I have datetime objects that I want to show up for users in their local time.
Using answered questions on here, I've come up with a jinja filter to 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)
return local_dt.strftime('%m/%d/%y @ %I:%M %p')
app.jinja_env.filters['local_dt'] = local_datetime
{{ user.last_login_at|local_dt }} # in my template
My thought was that it would run each time someone views the page (hence the filter) so that it will always show in the user's native timezone.
It shows up right on my development machine, but I'd like to make sure that get_localzone() is actually grabbing the user's local timezone and not always the server's.
My question is: How can I test if this is working correctly?