mirror of
https://github.com/agessaman/meshcore-bot.git
synced 2026-10-23 14:22:22 +00:00
feat(packet_capture): add UTC ISO 8601 timestamp method and update timestamp usage
- Introduced a new static method `_utc_iso_timestamp` to generate UTC ISO 8601 timestamps with a 'Z' suffix for compatibility. - Updated timestamp generation in `log_packet` and status message to utilize the new method, ensuring consistent timestamp formatting across the service. - Added a unit test to verify the correct format of the new timestamp method.
This commit is contained in:
1 parent
fca42c50a7
commit
a997f86a9f
2 files changed
+15
-3
No files matched your search
@@ -11,7 +11,7 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any, Optional
|
||||
|
||||
# Import meshcore
|
||||
@@ -393,6 +393,11 @@ class PacketCaptureService(BaseServicePlugin):
|
||||
ttl = 86400
|
||||
return iat, iat + ttl
|
||||
|
||||
@staticmethod
|
||||
def _utc_iso_timestamp() -> str:
|
||||
"""UTC ISO 8601 timestamp with Z suffix for broad consumer compatibility."""
|
||||
return datetime.now(timezone.utc).isoformat().replace("+00:00", "Z")
|
||||
|
||||
@staticmethod
|
||||
def _jwt_ttl_log_phrase(ttl_seconds: int) -> str:
|
||||
"""Short TTL description for log lines."""
|
||||
@@ -694,7 +699,7 @@ class PacketCaptureService(BaseServicePlugin):
|
||||
dict[str, Any]: Formatted packet dictionary.
|
||||
"""
|
||||
current_time = datetime.now()
|
||||
timestamp = current_time.isoformat()
|
||||
timestamp = self._utc_iso_timestamp()
|
||||
|
||||
# Remove 0x prefix if present
|
||||
clean_raw_hex = raw_hex.replace("0x", "").upper()
|
||||
@@ -1839,7 +1844,7 @@ class PacketCaptureService(BaseServicePlugin):
|
||||
|
||||
status_msg = {
|
||||
"status": status,
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
"timestamp": self._utc_iso_timestamp(),
|
||||
"origin": device_name,
|
||||
"origin_id": device_public_key,
|
||||
"model": firmware_info.get("model", "unknown"),
|
||||
|
||||
Reference in new issue
Block a user