# HG changeset patch # User Goffi # Date 1630068518 -7200 # Node ID 025ea418032f5d28282b7d089f3ea4342aec0782 # Parent d685299645fab173ec911f7854f8f0692f3667b7 tools (common/date_utils): parse `now` alone (when used without relative delta) diff -r d685299645fa -r 025ea418032f sat/tools/common/date_utils.py --- a/sat/tools/common/date_utils.py Fri Aug 27 14:48:29 2021 +0200 +++ b/sat/tools/common/date_utils.py Fri Aug 27 14:48:38 2021 +0200 @@ -25,6 +25,7 @@ from dateutil import tz, parser from dateutil.relativedelta import relativedelta from dateutil.utils import default_tzinfo +from dateutil.parser import ParserError from babel import dates import calendar import time @@ -50,9 +51,15 @@ value = str(value).strip() dayfirst = False if YEAR_FIRST_RE.match(value) else True - dt = default_tzinfo( - parser.parse(value, default=DEFAULT_DATETIME, dayfirst=dayfirst), - default_tz) + try: + dt = default_tzinfo( + parser.parse(value, default=DEFAULT_DATETIME, dayfirst=dayfirst), + default_tz) + except ParserError as e: + if value == "now": + dt = datetime.datetime.now(tz.tzutc()) + else: + raise e return calendar.timegm(dt.utctimetuple()) def date_parse_ext(value, default_tz=TZ_UTC):