From 5563a6d8c739aa64d3b1ec78d4c65498ac6c424b Mon Sep 17 00:00:00 2001 From: Rossen Georgiev Date: Tue, 16 Aug 2016 22:27:50 +0100 Subject: [PATCH] refactor total_seconds() for py2.6 comp --- aprslib/parsing/common.py | 3 ++- tests/test_parse_common.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/aprslib/parsing/common.py b/aprslib/parsing/common.py index 185215b..dd8d9cd 100644 --- a/aprslib/parsing/common.py +++ b/aprslib/parsing/common.py @@ -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) diff --git a/tests/test_parse_common.py b/tests/test_parse_common.py index fc4c84a..64190dc 100644 --- a/tests/test_parse_common.py +++ b/tests/test_parse_common.py @@ -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")