fix incorrect caputation of timestamp in some cases

This commit is contained in:
Rossen Georgiev 2016-08-16 21:50:21 +01:00
parent 8abcc85761
commit 9e6c292422
2 changed files with 2 additions and 5 deletions

View File

@ -1,5 +1,4 @@
import re
import time
from datetime import datetime
from aprslib import base91
from aprslib.exceptions import ParseError
@ -100,8 +99,7 @@ def parse_timestamp(body, packet_type=''):
else:
timestamp = "19700101000000"
timestamp = utc.strptime(timestamp, "%Y%m%d%H%M%S")
timestamp = time.mktime(timestamp.timetuple())
timestamp = int((utc.strptime(timestamp, "%Y%m%d%H%M%S") - datetime(1970, 1, 1)).total_seconds())
except Exception as exp:
timestamp = 0
logger.debug(exp)

View File

@ -2,7 +2,6 @@ import unittest2 as unittest
import string
from random import randint, randrange, sample
from datetime import datetime
import time
from aprslib import base91
from aprslib.parsing.common import *
@ -180,7 +179,7 @@ class TimestampTC(unittest.TestCase):
def test_timestamp_valid(self):
date = datetime.utcnow()
timestamp = time.mktime(date.timetuple())
timestamp = int((date - datetime(1970, 1, 1)).total_seconds())
# hhmmss format
body = date.strftime("%H%M%Shtext")