diff sat/tools/common/date_utils.py @ 3631:bef32f3ccc06

merge branche "@"
author Goffi <goffi@goffi.org>
date Fri, 27 Aug 2021 14:51:40 +0200
parents ab1fe6b25631 025ea418032f
children 92482cc80d0b
line wrap: on
line diff
--- a/sat/tools/common/date_utils.py	Fri Aug 27 08:49:45 2021 +0200
+++ b/sat/tools/common/date_utils.py	Fri Aug 27 14:51:40 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
@@ -64,9 +65,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):