Mercurial > libervia-backend
diff sat/tools/common/date_utils.py @ 2797:7968c8b7b5e1
tools (common): fixed dateutil.parser import
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 02 Feb 2019 01:12:54 +0100 |
parents | 003b8b4b56a7 |
children | 1b6547fb80da |
line wrap: on
line diff
--- a/sat/tools/common/date_utils.py Sat Feb 02 01:05:25 2019 +0100 +++ b/sat/tools/common/date_utils.py Sat Feb 02 01:12:54 2019 +0100 @@ -22,8 +22,7 @@ from sat.core.constants import Const as C from sat.core.i18n import _ import datetime -import dateutil -from dateutil import tz +from dateutil import tz, parser from dateutil.relativedelta import relativedelta from dateutil.utils import default_tzinfo from babel import dates @@ -42,21 +41,21 @@ def date_parse(value, default_tz=TZ_UTC): """Parse a date and return corresponding unix timestamp - @param value(unicode): date to parse, in any format supported by dateutil.parser + @param value(unicode): date to parse, in any format supported by parser @param default_tz(datetime.tzinfo): default timezone @return (int): timestamp """ - dt = default_tzinfo(dateutil.parser.parse(unicode(value), dayfirst=True), default_tz) + dt = default_tzinfo(parser.parse(unicode(value), dayfirst=True), default_tz) return calendar.timegm(dt.utctimetuple()) def date_parse_ext(value, default_tz=TZ_UTC): """Extended date parse which accept relative date - @param value(unicode): date to parse, in any format supported by dateutil.parser + @param value(unicode): date to parse, in any format supported by parser and with the hability to specify X days/weeks/months/years in the past or future. Relative date are specified either with something like `[main_date] +1 week` or with something like `3 days ago`, and it is case insensitive. [main_date] is - a date parsable by dateutil.parser, or empty to specify current date/time. + a date parsable by parser, or empty to specify current date/time. "now" can also be used to specify current date/time. @param default_tz(datetime.tzinfo): same as for date_parse @return (int): timestamp @@ -78,7 +77,7 @@ if not date or date == u"now": dt = datetime.datetime.now(tz.tzutc()) else: - dt = default_tzinfo(dateutil.parser.parse(date, dayfirst=True)) + dt = default_tzinfo(parser.parse(date, dayfirst=True)) quantity = int(m.group(u"quantity")) key = m.group(u"unit").lower() + u"s"