# HG changeset patch # User Goffi # Date 1495189991 -7200 # Node ID 228d208fb5db8645a03b803c7200be91000b9a9b # Parent fd4111075e006ba4edc66e20df9f58be246bd8fc core (tools/utils): added method to parse XMPP dates diff -r fd4111075e00 -r 228d208fb5db src/tools/utils.py --- a/src/tools/utils.py Thu May 04 00:36:03 2017 +0200 +++ b/src/tools/utils.py Fri May 19 12:33:11 2017 +0200 @@ -24,6 +24,8 @@ from sat.core.log import getLogger log = getLogger(__name__) import datetime +import dateutil +import calendar import time import sys import random @@ -55,6 +57,13 @@ template = u"{}T{}".format(template_date, template_time) if with_time else template_date return datetime.datetime.utcfromtimestamp(time.time() if timestamp is None else timestamp).strftime(template) +def date_parse(value): + """Parse a date and return corresponding unix timestamp + + @param value(unicode): date to parse, in any format supported by dateutil.parser + """ + return calendar.timegm(dateutil.parser.parse(unicode(value)).utctimetuple()) + def generatePassword(vocabulary=None, size=20): """Generate a password with random characters.