Fix: Use venue timezone for fixture date comparison in dashboard

- get_fixtures() now uses get_today_venue_date() instead of date.today()
- calculate_fixture_status() converts UTC start_time to venue timezone before date comparison
- Fixes fixtures not showing when start_time is today in local time but yesterday in UTC
parent fb58d186
......@@ -3988,6 +3988,7 @@ def get_fixtures():
from ..database.models import MatchModel
from datetime import datetime, date
from collections import defaultdict
from ..utils.timezone_utils import get_today_venue_date, utc_to_venue_datetime
session = api_bp.db_manager.get_session()
try:
......@@ -3999,14 +4000,15 @@ def get_fixtures():
fixtures_by_id[match.fixture_id].append(match)
fixtures_data = []
today = date.today()
# Use venue timezone for date comparison
today = get_today_venue_date(api_bp.db_manager)
for fixture_id, fixture_matches in fixtures_by_id.items():
# Sort matches by match_number for consistent ordering
fixture_matches.sort(key=lambda m: m.match_number)
# Calculate fixture-level status
fixture_status = calculate_fixture_status(fixture_matches, today)
# Calculate fixture-level status with venue timezone awareness
fixture_status = calculate_fixture_status(fixture_matches, today, api_bp.db_manager)
# Use the first match as the representative for the fixture
first_match = fixture_matches[0]
......@@ -4045,13 +4047,14 @@ def get_fixtures():
return jsonify({"error": str(e)}), 500
def calculate_fixture_status(matches, today):
def calculate_fixture_status(matches, today, db_manager=None):
"""
Calculate fixture status based on match statuses and timing.
Args:
matches: List of MatchModel objects for this fixture
today: Today's date
today: Today's date in venue timezone
db_manager: Database manager for timezone conversion (optional for backward compatibility)
Returns:
str: Fixture status ('pending', 'running', 'scheduled', 'bet', 'ingame', 'end')
......@@ -4066,11 +4069,19 @@ def calculate_fixture_status(matches, today):
if all(status == 'pending' for status in match_statuses):
return 'pending'
# Check if start time of first match is today and at least one match is pending
# Check if start time of first match is today (in venue timezone) and at least one match is pending
first_match = matches[0]
if (first_match.start_time and
if first_match.start_time and db_manager:
# Convert UTC start_time to venue timezone for proper date comparison
from ..utils.timezone_utils import utc_to_venue_datetime
venue_start_time = utc_to_venue_datetime(first_match.start_time, db_manager)
if (venue_start_time.date() == today and
any(status == 'pending' for status in match_statuses)):
return 'running'
elif (first_match.start_time and
first_match.start_time.date() == today and
any(status == 'pending' for status in match_statuses)):
# Fallback for backward compatibility (no db_manager)
return 'running'
# Otherwise, determine status based on the most advanced match status
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment