core (tools/utils): added method to parse XMPP dates
This commit is contained in:
parent
c8b4b77908
commit
1cfd34c38d
1 changed files with 9 additions and 0 deletions
|
|
@ -24,6 +24,8 @@ import os.path
|
||||||
from sat.core.log import getLogger
|
from sat.core.log import getLogger
|
||||||
log = getLogger(__name__)
|
log = getLogger(__name__)
|
||||||
import datetime
|
import datetime
|
||||||
|
import dateutil
|
||||||
|
import calendar
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
import random
|
import random
|
||||||
|
|
@ -55,6 +57,13 @@ def xmpp_date(timestamp=None, with_time=True):
|
||||||
template = u"{}T{}".format(template_date, template_time) if with_time else template_date
|
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)
|
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):
|
def generatePassword(vocabulary=None, size=20):
|
||||||
"""Generate a password with random characters.
|
"""Generate a password with random characters.
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue