refactor total_seconds() for py2.6 comp

This commit is contained in:
Rossen Georgiev 2016-08-16 22:27:50 +01:00
parent 566446bfd7
commit 5563a6d8c7
2 changed files with 4 additions and 2 deletions

View File

@ -99,7 +99,8 @@ def parse_timestamp(body, packet_type=''):
else:
timestamp = "19700101000000"
timestamp = int((utc.strptime(timestamp, "%Y%m%d%H%M%S") - datetime(1970, 1, 1)).total_seconds())
td = utc.strptime(timestamp, "%Y%m%d%H%M%S") - datetime(1970, 1, 1)
timestamp = int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
except Exception as exp:
timestamp = 0
logger.debug(exp)

View File

@ -179,7 +179,8 @@ class TimestampTC(unittest.TestCase):
def test_timestamp_valid(self):
date = datetime.utcnow()
timestamp = int((date - datetime(1970, 1, 1)).total_seconds())
td = date - datetime(1970, 1, 1)
timestamp = int((td.microseconds + (td.seconds + td.days * 24 * 3600) * 10**6) / 10**6)
# hhmmss format
body = date.strftime("%H%M%Shtext")