pythonutcapschedulerpytz

How to convert difference in hours to timezone in python?


I am currently working with apscheduler with multiple users located in different timezones.

There is no possibility to get the timezone from them automatically, so I need to do this with input data. Using a city is not that obvious to me as some might live in villages or near cities that are within timezones defined by other cities. So I was wondering, is there a possibility to do so using something like pytz module with a difference in hours with the server or is there anything better?

Pytz says the only way possible to do so is like:

amsterdam = timezone('Europe/Amsterdam')

But there is a city-defined timezone, which is not that universal. I want to unload the user as much as I can and free them from unnecessary work of looking up the suitable timezone for each predefined one.

I feel stuck and out of ideas. No success on the Internet so far.


Solution

  • Using AsyncIOScheduler, the timezone + hours is calculated as the following:

    scheduler = AsyncIOScheduler(timezone=f'Etc/GMT{user_time_zone}')
    

    Where user_time_zone is an str of int numbers from -14 to 9, with positive numbers going with +.