diff --git a/src/common/connection_handlers.py b/src/common/connection_handlers.py index 91cbd93d4..c4feea01f 100644 --- a/src/common/connection_handlers.py +++ b/src/common/connection_handlers.py @@ -24,7 +24,7 @@ import socket import sys from time import (altzone, daylight, gmtime, localtime, mktime, strftime, - strptime, time as time_time, timezone, tzname) + time as time_time, timezone, tzname) from calendar import timegm import socks5 @@ -1424,7 +1424,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, mtype = msg.getType() subject = msg.getSubject() # if not there, it's None tim = msg.getTimestamp() - tim = strptime(tim, '%Y%m%dT%H:%M:%S') + tim = helpers.datetime_tuple(tim) tim = localtime(timegm(tim)) frm = helpers.get_full_jid_from_iq(msg) jid = helpers.get_jid_from_iq(msg) @@ -1614,7 +1614,7 @@ class ConnectionHandlers(ConnectionVcard, ConnectionBytestream, ConnectionDisco, elif namespace == common.xmpp.NS_DELAY: # XEP-0091 tim = prs.getTimestamp() - tim = strptime(tim, '%Y%m%dT%H:%M:%S') + tim = helpers.datetime_tuple(tim) timestamp = localtime(timegm(tim)) elif namespace == 'http://delx.cjb.net/protocol/roster-subsync': # see http://trac.gajim.org/ticket/326 diff --git a/src/common/helpers.py b/src/common/helpers.py index b381b70c0..12865a24d 100644 --- a/src/common/helpers.py +++ b/src/common/helpers.py @@ -970,3 +970,15 @@ def get_avatar_path(prefix): if os.path.exists(file_): return file_ return None + +def datetime_tuple(timestamp): + '''Converts timestamp using strptime and the format: %Y%m%dT%H:%M:%S + Because of various datetime formats are used the following exceptions + are handled: + - Optional milliseconds appened to the string are removed + - XEP-082 datetime strings have all '-' cahrs removed to meet + the above format.''' + timestamp = timestamp.split('.')[0] + timestamp = timestamp.replace('-', '') + from time import strptime + return strptime(timestamp, '%Y%m%dT%H:%M:%S') diff --git a/src/common/zeroconf/connection_handlers_zeroconf.py b/src/common/zeroconf/connection_handlers_zeroconf.py index 165b318d4..eaa2f6a17 100644 --- a/src/common/zeroconf/connection_handlers_zeroconf.py +++ b/src/common/zeroconf/connection_handlers_zeroconf.py @@ -640,7 +640,7 @@ class ConnectionHandlersZeroconf(ConnectionVcard, ConnectionBytestream): mtype = msg.getType() subject = msg.getSubject() # if not there, it's None tim = msg.getTimestamp() - tim = time.strptime(tim, '%Y%m%dT%H:%M:%S') + tim = helpers.datetime_tuple(tim) tim = time.localtime(timegm(tim)) frm = msg.getFrom() if frm == None: