Use timezone-aware UTC datetimes for timestamp conversions

Agent-Logs-Url: https://github.com/christianlouis/dmarq/sessions/ea784ce3-2c1c-45f8-ad6d-46e92cf15ed7

Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-03-29 15:45:26 +00:00
parent e51fbe755e
commit 6329d3aa35
2 changed files with 5 additions and 5 deletions
+2 -2
View File
@@ -1,4 +1,4 @@
from datetime import datetime
from datetime import datetime, timezone
from typing import Any, Dict, List, Optional
from fastapi import APIRouter, HTTPException, Path, Query, status
@@ -318,7 +318,7 @@ def _build_compliance_timeline(store: ReportStore, domain: str) -> List[Timeline
# Use begin_date to determine the day of this report
begin = report.get("begin_date", 0)
if isinstance(begin, (int, float)) and begin > 0:
date_str = datetime.fromtimestamp(begin).strftime("%Y-%m-%d")
date_str = datetime.fromtimestamp(begin, tz=timezone.utc).strftime("%Y-%m-%d")
elif isinstance(begin, str):
# Handle ISO-format strings
try:
+3 -3
View File
@@ -1,7 +1,7 @@
import json
import logging
import os
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any, Dict, List, Optional
from sqlalchemy import case, func
@@ -319,7 +319,7 @@ class StatsSummarizer:
Groups reports by their date range and calculates daily compliance rates.
"""
cutoff = datetime.now() - timedelta(days=days)
cutoff = datetime.now(timezone.utc) - timedelta(days=days)
cutoff_ts = int(cutoff.timestamp())
# Build the base query for records within the time window
@@ -349,7 +349,7 @@ class StatsSummarizer:
# Convert timestamps to dates and aggregate per day
daily: Dict[str, Dict[str, int]] = {}
for row in results:
date_str = datetime.fromtimestamp(row.begin_date).strftime("%Y-%m-%d")
date_str = datetime.fromtimestamp(row.begin_date, tz=timezone.utc).strftime("%Y-%m-%d")
if date_str not in daily:
daily[date_str] = {"total": 0, "passed": 0}
daily[date_str]["total"] += int(row.total)