tz aware as default return

This commit is contained in:
Daniel Tsvetkov 2019-03-14 18:25:05 -07:00
parent c35a446150
commit 373afad423
2 changed files with 5 additions and 2 deletions

0
__init__.py Normal file
View File

7
tz.py
View File

@ -9,6 +9,7 @@ import dateparser
from pytz.exceptions import UnknownTimeZoneError
FUZZ_THRESHOLD = 70
ISO_FORMAT = '%Y-%m-%dT%H:%M:%S%z'
DEFAULT_FORMAT = '%Y-%m-%d %H:%M:%S%z'
basepath = os.path.dirname(os.path.abspath(__file__))
@ -20,6 +21,7 @@ def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument('query', nargs='*', help="<datetime-like> to <timezone-like or location string>")
parser.add_argument('--format', dest='format', default=DEFAULT_FORMAT)
parser.add_argument('--iso', dest='iso', action='store_true')
parser.add_argument('--debug', dest='debug', action='store_true')
args = parser.parse_args()
return args
@ -200,7 +202,7 @@ def parse_query(query):
def solve_query(human_dt, human_tz_loc):
try:
# first try parsing the timezone from user input
result = dateparser.parse(human_dt)
result = dateparser.parse(human_dt, settings={'RETURN_AS_TIMEZONE_AWARE': True})
logger.debug("human_dt result: {}".format(result))
if human_tz_loc:
# if the human_tz_loc contains /, assume it's a timezone which could be
@ -252,7 +254,8 @@ def query_to_format_result(query, fmt=DEFAULT_FORMAT):
def main(args):
formated_result = query_to_format_result(args.query, args.format)
fmt = ISO_FORMAT if args.iso else args.format
formated_result = query_to_format_result(args.query, fmt)
print(formated_result)