translation
This commit is contained in:
parent
39527abc0a
commit
f5e51bbdab
@ -68,11 +68,7 @@ def handler_timezone_translation(dt_s: str, timezone_like_s: str) -> dict:
|
||||
else:
|
||||
offset = tz.get('tz_offset')
|
||||
dst_dt = dt_tz_translation(src_dt, offset)
|
||||
return dict(
|
||||
src_dt=dt_pretty(src_dt),
|
||||
dst_dt=dt_pretty(dst_dt),
|
||||
tz=tz,
|
||||
)
|
||||
return src_dt, dst_dt, tz
|
||||
|
||||
|
||||
def handler_generic_parser(dt_s: str) -> datetime:
|
||||
@ -137,7 +133,7 @@ def tokenize(s):
|
||||
except Exception as e:
|
||||
continue
|
||||
if result is not None:
|
||||
solutions.append((h.__name__, (result,), t))
|
||||
solutions.append((h.__name__, result, t))
|
||||
return solutions
|
||||
|
||||
|
||||
@ -185,7 +181,6 @@ def dt_pretty(dt):
|
||||
rv["locale_month_short"] = dt.strftime("%b")
|
||||
rv["tz_name"] = dt.strftime("%Z")
|
||||
rv["tz_offset"] = dt.strftime("%z")
|
||||
rv["tz"] = resolve_timezone(dt.strftime("%z"))
|
||||
rv["hh:mm"] = dt.strftime("%H:%M")
|
||||
rv["locale_time"] = dt.strftime("%X")
|
||||
rv["locale_date"] = dt.strftime("%x")
|
||||
@ -283,20 +278,21 @@ def resolve_query(query):
|
||||
element["handler"] = handler
|
||||
element["query_type"] = query_type
|
||||
if query_type == QUERY_TYPE_DT:
|
||||
element["dt"] = dt_pretty(results[0])
|
||||
element["dt"] = dt_pretty(results)
|
||||
elif query_type == QUERY_TYPE_DT_TR:
|
||||
element["src_dt"] = dt_pretty(results[0])
|
||||
element["dst_dt"] = dt_pretty(results[1])
|
||||
element["tz"] = results[2]
|
||||
elif query_type == QUERY_TYPE_TZ:
|
||||
element["tz"] = results[0]
|
||||
element["tz"] = results
|
||||
elif query_type == QUERY_TYPE_TD:
|
||||
element["timedelta"] = results[0]
|
||||
element["timedelta"] = results
|
||||
rv["solutions"].append(element)
|
||||
return rv
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
# query = "time in sofia"
|
||||
# query = "2020-02-11T13:01:05+0100 to sofia"
|
||||
query = ' '.join(sys.argv[1:])
|
||||
result = resolve_query(query)
|
||||
pretty_print_dict(result)
|
||||
|
@ -508,7 +508,7 @@ def dt_tz_translation(dt: datetime, to_tz_offset: str, from_tz_offset: str = "+0
|
||||
from_shh, from_mm = from_tz_offset.split(':')
|
||||
else:
|
||||
from_shh, from_mm = from_tz_offset[:-2], to_tz_offset[-2:]
|
||||
tzinfo = tzinfo_from_offset(to_tz_offset)
|
||||
tzinfo = tzinfo_from_offset(to_tz_offset)[0]
|
||||
if dt.tzinfo:
|
||||
return dt.astimezone(tzinfo)
|
||||
r_dt = dt + timedelta(hours=int(to_shh), minutes=int(to_mm)) - timedelta(
|
||||
|
Loading…
Reference in New Issue
Block a user