Mercurial > libervia-backend
changeset 2238:228d208fb5db
core (tools/utils): added method to parse XMPP dates
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 19 May 2017 12:33:11 +0200 |
parents | fd4111075e00 |
children | 17502e74c046 |
files | src/tools/utils.py |
diffstat | 1 files changed, 9 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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.