better timestamp handling. Fixes #3818

This commit is contained in:
Yann Leboulanger 2016-03-31 22:46:44 +02:00
parent 8d57da9d39
commit 902c3d59c6
2 changed files with 26 additions and 7 deletions

View File

@ -94,7 +94,11 @@ class HelperEvent:
self.gc_control = minimized.get(self.jid)
def _generate_timestamp(self, tag):
tim = helpers.datetime_tuple(tag)
try:
tim = helpers.datetime_tuple(tag)
except Exception:
log.error('wrong timestamp, ignoring it: ' + tag)
tim = localtime()
self.timestamp = localtime(timegm(tim))
def get_chatstate(self):

View File

@ -44,6 +44,7 @@ import shlex
from common import caps_cache
import socket
import time
import datetime
from gi.repository import GObject
from encodings.punycode import punycode_encode
@ -598,12 +599,26 @@ def datetime_tuple(timestamp):
- XEP-082 datetime strings have all '-' cahrs removed to meet
the above format.
"""
timestamp = timestamp.split('.')[0]
timestamp = timestamp.replace('-', '')
timestamp = timestamp.replace('z', '')
timestamp = timestamp.replace('Z', '')
from time import strptime
return strptime(timestamp, '%Y%m%dT%H:%M:%S')
date, tim = timestamp.split('T', 1)
date = date.replace('-', '')
tim = tim.replace('z', '')
tim = tim.replace('Z', '')
zone = None
if '+' in tim:
sign = -1
tim, zone = tim.split('+', 1)
if '-' in tim:
sign = 1
tim, zone = tim.split('-', 1)
tim = tim.split('.')[0]
tim = time.strptime(date + 'T' + tim, '%Y%m%dT%H:%M:%S')
if zone:
tim = datetime.datetime.fromtimestamp(time.mktime(t))
zone = strptime.time(zone, '%H:%M')
zone = datetime.timedelta(hours=zone.tm_hour, minutes=zone.tm_min)
tim += zone * sign
tim = tim.timetuple()
return tim
from common import gajim
if gajim.HAVE_PYCURL: