# HG changeset patch # User Goffi # Date 1440691151 -7200 # Node ID 566908d483f655be3b485aed2fa8f30c793a2c41 # Parent cb1b0fe104156ecad264fa055671e6fa21558622 core (utils): added a method to generate XEP-0082 style dates diff -r cb1b0fe10415 -r 566908d483f6 src/tools/utils.py --- a/src/tools/utils.py Thu Aug 27 17:59:01 2015 +0200 +++ b/src/tools/utils.py Thu Aug 27 17:59:11 2015 +0200 @@ -23,12 +23,15 @@ import os.path from sat.core.log import getLogger log = getLogger(__name__) +import datetime +import time def clean_ustr(ustr): """Clean unicode string - remove special characters from unicode string""" + remove special characters from unicode string + """ def valid_chars(unicode_source): for char in unicode_source: if unicodedata.category(char) == 'Cc' and char!='\n': @@ -36,6 +39,20 @@ yield char return ''.join(valid_chars(ustr)) +def xmpp_date(timestamp=None, with_time=True): + """Return date according to XEP-0082 specification + + to avoid reveling the timezone, we always return UTC dates + @param timestamp(None, float): posix timestamp. If None current time will be used + @param with_time(bool): if True include the time + @return(unicode): XEP-0082 formatted date and time + """ + template_date = u"%Y-%m-%d" + template_time = u"%H:%M:%SZ" + 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 getRepositoryData(module, as_string=True): """Retrieve info on current mecurial repository