From b2d161a0e6304130483a625c7920858b43c109ba Mon Sep 17 00:00:00 2001 From: Daniel Tsvetkov Date: Sat, 25 Apr 2020 19:47:27 +0200 Subject: [PATCH] update tww --- tww/data/.cache.csv | 1 + tww/tww.py | 17 ++++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/tww/data/.cache.csv b/tww/data/.cache.csv index fcb7ce2..4486de0 100644 --- a/tww/data/.cache.csv +++ b/tww/data/.cache.csv @@ -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 diff --git a/tww/tww.py b/tww/tww.py index eb75505..4bee5c5 100644 --- a/tww/tww.py +++ b/tww/tww.py @@ -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):