Using python, the most accurate way to automatically determine the current time zone of users

I checked that dateutils.tz.tzlocal () does not work on heroku, and even if that happened, would it not be easy to get tz from the computer OS, and not from users?

With the exception of saving users timezone, is there a way to determine where the request comes from? (I use a flask)

Twitter has a setting for setting the time zone, but I wonder how they determine what should be the default, and how it will work when the user does not log in.

+6
source share
2 answers

You can use Javascript and set the client time zone in a cookie. You can even use an AJAX request and then send the offset to the server and save it in the client session.

var offset = new Date().getTimezoneOffset(); 

Description

The time zone offset is the difference in minutes between GMT and local time. Note that> this means that the offset is positive if the local time zone is outside UTC and negative if it is ahead. For example, if your time zone is UTC + 10 (Australian Eastern Standard Time), -600 will be returned. Summer time does not allow this value to be constant even for a given language

Mozilla Javascript Help: getTimezoneOffset

+9
source

If you can easily get the user's IP address from a flask (perhaps from a request object?), You can use geolocation. For instance. via http://www.hostip.info/ .

This is probably not 100% reliable. For example, if someone uses a VPN or other proxy server, you will not see his β€œreal” IP address.

+1
source

Source: https://habr.com/ru/post/923891/


All Articles