better timestamp handling. Fixes #3818
This commit is contained in:
		
							parent
							
								
									8d57da9d39
								
							
						
					
					
						commit
						902c3d59c6
					
				
					 2 changed files with 26 additions and 7 deletions
				
			
		|  | @ -94,7 +94,11 @@ class HelperEvent: | ||||||
|             self.gc_control = minimized.get(self.jid) |             self.gc_control = minimized.get(self.jid) | ||||||
| 
 | 
 | ||||||
|     def _generate_timestamp(self, tag): |     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)) |         self.timestamp = localtime(timegm(tim)) | ||||||
| 
 | 
 | ||||||
|     def get_chatstate(self): |     def get_chatstate(self): | ||||||
|  |  | ||||||
|  | @ -44,6 +44,7 @@ import shlex | ||||||
| from common import caps_cache | from common import caps_cache | ||||||
| import socket | import socket | ||||||
| import time | import time | ||||||
|  | import datetime | ||||||
| 
 | 
 | ||||||
| from gi.repository import GObject | from gi.repository import GObject | ||||||
| from encodings.punycode import punycode_encode | from encodings.punycode import punycode_encode | ||||||
|  | @ -598,12 +599,26 @@ def datetime_tuple(timestamp): | ||||||
|             - XEP-082 datetime strings have all '-' cahrs removed to meet |             - XEP-082 datetime strings have all '-' cahrs removed to meet | ||||||
|               the above format. |               the above format. | ||||||
|     """ |     """ | ||||||
|     timestamp = timestamp.split('.')[0] |     date, tim = timestamp.split('T', 1) | ||||||
|     timestamp = timestamp.replace('-', '') |     date = date.replace('-', '') | ||||||
|     timestamp = timestamp.replace('z', '') |     tim = tim.replace('z', '') | ||||||
|     timestamp = timestamp.replace('Z', '') |     tim = tim.replace('Z', '') | ||||||
|     from time import strptime |     zone = None | ||||||
|     return strptime(timestamp, '%Y%m%dT%H:%M:%S') |     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 | from common import gajim | ||||||
| if gajim.HAVE_PYCURL: | if gajim.HAVE_PYCURL: | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue