fix: timezone-aware datetime for elapsed timer in screen API
This commit is contained in:
@@ -8,7 +8,7 @@ from app.models.match import Match, MatchPlayer, MatchStatus
|
||||
from app.models.player import Player
|
||||
from app.models.tournament import Tournament, TournamentStatus
|
||||
from app.services.tournament import get_bracket_data
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
|
||||
router = APIRouter(prefix="/screen", tags=["screen"])
|
||||
|
||||
@@ -47,7 +47,11 @@ def get_court_display(court_id: int, db: Session = Depends(get_db)):
|
||||
|
||||
elapsed = None
|
||||
if active_match.started_at:
|
||||
elapsed = int((datetime.utcnow() - active_match.started_at).total_seconds())
|
||||
now = datetime.now(timezone.utc)
|
||||
started = active_match.started_at
|
||||
if started.tzinfo is None:
|
||||
started = started.replace(tzinfo=timezone.utc)
|
||||
elapsed = int((now - started).total_seconds())
|
||||
|
||||
match_data = {
|
||||
"id": active_match.id,
|
||||
@@ -89,7 +93,7 @@ def get_court_display(court_id: int, db: Session = Depends(get_db)):
|
||||
},
|
||||
"active_match": match_data,
|
||||
"recent_matches": recent,
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
|
||||
|
||||
@@ -152,5 +156,5 @@ def get_overview(db: Session = Depends(get_db)):
|
||||
}
|
||||
for i, p in enumerate(top_players)
|
||||
],
|
||||
"timestamp": datetime.utcnow().isoformat(),
|
||||
"timestamp": datetime.now(timezone.utc).isoformat(),
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ except Exception as e:
|
||||
done
|
||||
|
||||
echo "Running seed..."
|
||||
cd /app && python seed.py 2>&1 && echo "Seed complete" || echo "Seed failed or already ran (continuing)"
|
||||
cd /app && python seed.py && echo "Seed complete" || echo "Seed failed (continuing)"
|
||||
|
||||
echo "Starting server..."
|
||||
exec uvicorn app.main:app --host 0.0.0.0 --port 8000
|
||||
|
||||
Reference in New Issue
Block a user