提交 6e66b74b 编写于 作者: T t_max

fix: fix check timestamp data

上级 e12bb340
...@@ -24,26 +24,12 @@ from util.log import * ...@@ -24,26 +24,12 @@ from util.log import *
from util.constant import * from util.constant import *
# from datetime import timezone # from datetime import timezone
from tzlocal import get_localzone
import pytz
import time import time
def _locaTzTimeStamp(utctimestamp): def _parse_ns_timestamp(timestr):
tz = get_localzone() dt_obj = datetime.datetime.strptime(timestr[:len(timestr)-3], "%Y-%m-%d %H:%M:%S.%f")
temptz = str(tz) tz = int(int((dt_obj-datetime.datetime.fromtimestamp(0,dt_obj.tzinfo)).total_seconds())*1e9) + int(dt_obj.microsecond * 1000) + int(timestr[-3:])
localtz = pytz.timezone(temptz) return tz
defUtctimestamp=1035640800
local_dt = datetime.datetime(2002, 10, 27, 6, 0, 0, tzinfo=localtz)
defLocaltimestamp = time.mktime(local_dt.timetuple())
deltaTzTime = int(defLocaltimestamp)-int(defUtctimestamp)
temp = int(str(utctimestamp)[0:10])
tempOther = str(utctimestamp)[10-len(str(utctimestamp)):]
localtemp = deltaTzTime + temp
localAll = str(localtemp) + str(tempOther)
localtimestamp = int(localAll)
print(f"local timezone is {localtimestamp}, Deltel time is {deltaTzTime}s")
return localtimestamp
def _parse_datetime(timestr): def _parse_datetime(timestr):
...@@ -268,8 +254,7 @@ class TDSql: ...@@ -268,8 +254,7 @@ class TDSql:
# suppose user want to check nanosecond timestamp if a longer data passed`` # suppose user want to check nanosecond timestamp if a longer data passed``
if isinstance(data,str) : if isinstance(data,str) :
if (len(data) >= 28): if (len(data) >= 28):
resultData = _locaTzTimeStamp(self.queryResult[row][col]) if self.queryResult[row][col] == _parse_ns_timestamp(data):
if pd.to_datetime(resultData) == pd.to_datetime(data):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{pd.to_datetime(resultData)} == expect:{data}") # tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{pd.to_datetime(resultData)} == expect:{data}")
tdLog.info("check successfully") tdLog.info("check successfully")
else: else:
...@@ -277,7 +262,7 @@ class TDSql: ...@@ -277,7 +262,7 @@ class TDSql:
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
else: else:
if self.queryResult[row][col] == _parse_datetime(data): if self.queryResult[row][col].astimezone(datetime.timezone.utc) == _parse_datetime(data).astimezone(datetime.timezone.utc):
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}") # tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{data}")
tdLog.info("check successfully") tdLog.info("check successfully")
else: else:
...@@ -287,18 +272,31 @@ class TDSql: ...@@ -287,18 +272,31 @@ class TDSql:
return return
elif isinstance(data,int) : elif isinstance(data,int) :
if len(str(data)) == 16 : if len(str(data)) == 16 :
unitTime = 'us' precision = 'us'
elif len(str(data)) == 13 : elif len(str(data)) == 13 :
unitTime = 'ms' precision = 'ms'
elif len(str(data)) == 19 : elif len(str(data)) == 19 :
unitTime = 'ns' precision = 'ns'
else: else:
caller = inspect.getframeinfo(inspect.stack()[1][0]) caller = inspect.getframeinfo(inspect.stack()[1][0])
args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data) args = (caller.filename, caller.lineno, self.sql, row, col, self.queryResult[row][col], data)
tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args) tdLog.exit("%s(%d) failed: sql:%s row:%d col:%d data:%s != expect:%s" % args)
resultData = pd.to_datetime(_locaTzTimeStamp(data),unit=unitTime) return
if resultData == self.queryResult[row][col] : success = False
# tdLog.info(f"sql:{self.sql}, row:{row} col:{col} data:{self.queryResult[row][col]} == expect:{resultData}") if precision == 'ms':
dt_obj = self.queryResult[row][col]
tz = int(int((dt_obj-datetime.datetime.fromtimestamp(0,dt_obj.tzinfo)).total_seconds())*1000) + int(dt_obj.microsecond/1000)
if tz == data:
success = True
elif precision == 'us':
dt_obj = self.queryResult[row][col]
tz = int(int((dt_obj-datetime.datetime.fromtimestamp(0,dt_obj.tzinfo)).total_seconds())*1e6) + int(dt_obj.microsecond)
if tz == data:
success = True
elif precision == 'ns':
if data == self.queryResult[row][col]:
success = True
if success:
tdLog.info("check successfully") tdLog.info("check successfully")
else: else:
caller = inspect.getframeinfo(inspect.stack()[1][0]) caller = inspect.getframeinfo(inspect.stack()[1][0])
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册