tz aware as default return
This commit is contained in:
parent
c35a446150
commit
373afad423
0
__init__.py
Normal file
0
__init__.py
Normal file
7
tz.py
7
tz.py
@ -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)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user