HPI/my/core/time.py
Dima Gerasimov e92ca215e3 Adapt takeout and twitter configs to the new pattern
Works fairly well so far?
2020-05-10 15:56:57 +01:00

17 lines
462 B
Python

from functools import lru_cache
from datetime import datetime, tzinfo
import pytz # type: ignore
# https://gist.github.com/edwardabraham/8680198
tz_lookup = {
pytz.timezone(x).localize(datetime.now()).tzname(): pytz.timezone(x)
for x in pytz.all_timezones
}
tz_lookup['UTC'] = pytz.utc # ugh. otherwise it'z Zulu...
# TODO dammit, lru_cache interferes with mypy?
@lru_cache(None)
def abbr_to_timezone(abbr: str) -> tzinfo:
return tz_lookup[abbr]