update tww

This commit is contained in:
Daniel Tsvetkov 2020-04-25 19:47:27 +02:00
parent 8430260527
commit b2d161a0e6
2 changed files with 15 additions and 3 deletions

View File

@ -45,3 +45,4 @@ mountain view,14.1194444,15.3133335
in,6.9833333,171.6999969
ind,20.0,77.0
indi,20.0,77.0
local,37.6666667,-1.7

1 sofia 42.6975135 23.3241463
45 in 6.9833333 171.6999969
46 ind 20.0 77.0
47 indi 20.0 77.0
48 local 37.6666667 -1.7

View File

@ -259,6 +259,15 @@ def resolve_timezone(query):
# if the human_tz_loc contains /, assume it's a timezone which could be
# incorrectly written with small letters - need Continent/City
normal_query = query.lower().strip()
if normal_query in ['local']:
local_iana = get_local_tzname_iana()
local_offset = get_local_tz_offset()
return {
"query": query,
"normal_query": normal_query,
"tz_offset": local_offset,
"tz_name": local_iana,
}
found_from_iana_tz = NORMALIZED_TZ_DICT.get(normal_query, "")
found_from_abbr_tzs = list(NORMALIZED_TZ_ABBR.get(normal_query, set()))
found_from_offset_tz, offset_tzs = find_from_offset(normal_query)
@ -319,7 +328,7 @@ def resolve_timezone(query):
}
def solve_query(human_dt, human_tz_loc):
def solve_query(human_dt, human_tz_loc=None):
try:
# first try parsing the timezone from user input
result = dateparser.parse(human_dt, settings={'RETURN_AS_TIMEZONE_AWARE': True})
@ -604,8 +613,10 @@ def get_local_tzname_iana():
def get_local_tz_offset():
return format_offset_from_timedelta(
datetime.now(tzlocal()).tzinfo._std_offset)
now = datetime.now(tzlocal())
if now.tzinfo._isdst(now):
return format_offset_from_timedelta(now.tzinfo._dst_offset)
return format_offset_from_timedelta(now.tzinfo._std_offset)
def tzname_to_tz_offset(tzname_iana: str):