Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
3625:6559c0f847d4 | 3631:bef32f3ccc06 |
---|---|
23 from sat.core.i18n import _ | 23 from sat.core.i18n import _ |
24 import datetime | 24 import datetime |
25 from dateutil import tz, parser | 25 from dateutil import tz, parser |
26 from dateutil.relativedelta import relativedelta | 26 from dateutil.relativedelta import relativedelta |
27 from dateutil.utils import default_tzinfo | 27 from dateutil.utils import default_tzinfo |
28 from dateutil.parser import ParserError | |
28 from babel import dates | 29 from babel import dates |
29 import calendar | 30 import calendar |
30 import time | 31 import time |
31 import re | 32 import re |
32 | 33 |
62 @return (int): timestamp | 63 @return (int): timestamp |
63 """ | 64 """ |
64 value = str(value).strip() | 65 value = str(value).strip() |
65 dayfirst = False if YEAR_FIRST_RE.match(value) else True | 66 dayfirst = False if YEAR_FIRST_RE.match(value) else True |
66 | 67 |
67 dt = default_tzinfo( | 68 try: |
68 parser.parse(value, default=DEFAULT_DATETIME, dayfirst=dayfirst), | 69 dt = default_tzinfo( |
69 default_tz) | 70 parser.parse(value, default=DEFAULT_DATETIME, dayfirst=dayfirst), |
71 default_tz) | |
72 except ParserError as e: | |
73 if value == "now": | |
74 dt = datetime.datetime.now(tz.tzutc()) | |
75 else: | |
76 raise e | |
70 return calendar.timegm(dt.utctimetuple()) | 77 return calendar.timegm(dt.utctimetuple()) |
71 | 78 |
72 def date_parse_ext(value, default_tz=TZ_UTC): | 79 def date_parse_ext(value, default_tz=TZ_UTC): |
73 """Extended date parse which accept relative date | 80 """Extended date parse which accept relative date |
74 | 81 |