1
0
mirror of https://github.com/EDCD/EDMarketConnector.git synced 2025-04-18 18:07:37 +03:00

Fix handling of edproxy UTC timestamps

Courtesy of @andrewgoz. Fixes #107.
This commit is contained in:
Jonathan Harris 2016-04-26 17:13:58 +01:00
parent 9559a7a700
commit 58175d8ba9

View File

@ -9,6 +9,7 @@ import sys
import threading
from time import time, strptime, mktime
from datetime import datetime
from calendar import timegm
if __debug__:
from traceback import print_exc
@ -113,7 +114,7 @@ class _EDProxy:
s.settimeout(0)
s.sendall(json.dumps({
'Type' : 'Init',
'DateUtc' : datetime.now().isoformat(),
'DateUtc' : datetime.utcnow().isoformat(),
'StartTime' : 'now',
'Register' : [ 'System' ],
}))
@ -132,7 +133,7 @@ class _EDProxy:
msg = json.loads(s.recv(self.MESSAGE_MAX))
if msg['Type'] == self.MESSAGE_SYSTEM:
if 'DateUtc' in msg:
timestamp = mktime(datetime.strptime(msg['DateUtc'], '%Y-%m-%d %H:%M:%S').utctimetuple())
timestamp = timegm(datetime.strptime(msg['DateUtc'], '%Y-%m-%d %H:%M:%S').utctimetuple())
else:
timestamp = mktime(strptime(msg['Date'], '%Y-%m-%d %H:%M:%S')) # from local time
self.last_event = (timestamp, msg['System'])