feat:增加批量插入和查询日志告警功能
This commit is contained in:
25
utils/time.py
Normal file
25
utils/time.py
Normal file
@@ -0,0 +1,25 @@
|
||||
from datetime import datetime
|
||||
from typing import Tuple
|
||||
|
||||
|
||||
def get_timestamp_range(ts: int, delta_seconds: int = 5, unit: str = "microseconds") -> Tuple[int, int]:
|
||||
"""
|
||||
返回时间戳前后delta_seconds秒的范围(单位与输入一致)
|
||||
"""
|
||||
if ts <= 0:
|
||||
return 0, 0
|
||||
|
||||
scale = {
|
||||
"seconds": 1,
|
||||
"milliseconds": 1000,
|
||||
"microseconds": 1_000_000,
|
||||
"nanoseconds": 1_000_000_000
|
||||
|
||||
}.get(unit, 1_000_000) # 默认微秒
|
||||
|
||||
delta = delta_seconds * scale
|
||||
return ts - delta, ts + delta
|
||||
|
||||
|
||||
def format_timestamp(timestamp: int) -> str:
|
||||
return datetime.fromtimestamp(timestamp / 1_000_000).strftime("%Y-%m-%d %H:%M:%S")
|
||||
Reference in New Issue
Block a user