refactor total_seconds() for py2.6 comp
This commit is contained in:
parent
566446bfd7
commit
5563a6d8c7
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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")
|
||||
|
|
|
|||
Loading…
Reference in New Issue