Fix: Use venue timezone for fixture filtering in dashboard frontend

- API now returns is_today, is_past, and fixture_venue_date flags
- JavaScript filterFixtures() uses server-provided is_past flag instead of browser timezone
- renderFixturesTable() uses server-provided is_today/is_past for date badges
- Fixes fixtures not showing when browser timezone differs from venue timezone
parent 0649b7c9
...@@ -4013,6 +4013,16 @@ def get_fixtures(): ...@@ -4013,6 +4013,16 @@ def get_fixtures():
# Use the first match as the representative for the fixture # Use the first match as the representative for the fixture
first_match = fixture_matches[0] first_match = fixture_matches[0]
# Determine fixture date in venue timezone for proper filtering
fixture_venue_date = None
is_today = False
is_past = False
if first_match.start_time and db_manager:
venue_start_time = utc_to_venue_datetime(first_match.start_time, api_bp.db_manager)
fixture_venue_date = venue_start_time.date()
is_today = (fixture_venue_date == today)
is_past = (fixture_venue_date < today)
# Create fixture data structure # Create fixture data structure
fixture_data = { fixture_data = {
'id': first_match.id, 'id': first_match.id,
...@@ -4025,7 +4035,10 @@ def get_fixtures(): ...@@ -4025,7 +4035,10 @@ def get_fixtures():
'created_at': first_match.created_at.isoformat(), 'created_at': first_match.created_at.isoformat(),
'fixture_status': fixture_status, 'fixture_status': fixture_status,
'match_count': len(fixture_matches), 'match_count': len(fixture_matches),
'matches': [match.to_dict() for match in fixture_matches] 'matches': [match.to_dict() for match in fixture_matches],
'is_today': is_today,
'is_past': is_past,
'fixture_venue_date': fixture_venue_date.isoformat() if fixture_venue_date else None
} }
fixtures_data.append(fixture_data) fixtures_data.append(fixture_data)
......
...@@ -363,22 +363,13 @@ function filterFixtures() { ...@@ -363,22 +363,13 @@ function filterFixtures() {
const pastFilter = document.getElementById('past-filter').value; const pastFilter = document.getElementById('past-filter').value;
const searchTerm = document.getElementById('search-input').value.toLowerCase(); const searchTerm = document.getElementById('search-input').value.toLowerCase();
// Get today's date (start of day)
const today = new Date();
today.setHours(0, 0, 0, 0);
let filteredFixtures = allFixtures.filter(fixture => { let filteredFixtures = allFixtures.filter(fixture => {
// Past fixtures filter // Past fixtures filter - use server-provided is_past flag (venue timezone aware)
if (pastFilter === 'hide') { if (pastFilter === 'hide') {
// Hide past fixtures by default // Hide past fixtures by default - use server's is_past flag
if (fixture.start_time) { if (fixture.is_past === true) {
const fixtureDate = new Date(fixture.start_time); return false; // Hide past fixtures
fixtureDate.setHours(0, 0, 0, 0);
if (fixtureDate < today) {
return false; // Hide past fixtures
}
} }
// Show fixtures with no start_time or future/today start_time
} }
// If pastFilter is 'show', show all fixtures regardless of date // If pastFilter is 'show', show all fixtures regardless of date
...@@ -437,25 +428,27 @@ function renderFixturesTable(fixtures) { ...@@ -437,25 +428,27 @@ function renderFixturesTable(fixtures) {
const startTimeDisplay = fixture.start_time ? new Date(fixture.start_time).toLocaleString() : 'Not set'; const startTimeDisplay = fixture.start_time ? new Date(fixture.start_time).toLocaleString() : 'Not set';
const fixtureDate = fixture.start_time ? new Date(fixture.start_time).toLocaleDateString() : 'Not set'; const fixtureDate = fixture.start_time ? new Date(fixture.start_time).toLocaleDateString() : 'Not set';
// Determine if this is yesterday, today, or other date // Determine if this is yesterday, today, or other date using server-provided flags
let dateBadge = ''; let dateBadge = '';
if (fixture.start_time) { if (fixture.is_today === true) {
const matchDate = new Date(fixture.start_time); dateBadge = '<span class="badge bg-success">Today</span>';
const today = new Date(); } else if (fixture.is_past === true) {
const yesterday = new Date(today); // Check if it's yesterday (past but within 1 day)
yesterday.setDate(yesterday.getDate() - 1); if (fixture.fixture_venue_date) {
const venueDate = new Date(fixture.fixture_venue_date);
const matchDay = new Date(matchDate.getFullYear(), matchDate.getMonth(), matchDate.getDate()); const today = new Date();
const todayDay = new Date(today.getFullYear(), today.getMonth(), today.getDate()); const diffTime = today.getTime() - venueDate.getTime();
const yesterdayDay = new Date(yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate()); const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (diffDays === 1) {
if (matchDay.getTime() === yesterdayDay.getTime()) { dateBadge = '<span class="badge bg-warning">Yesterday</span>';
dateBadge = '<span class="badge bg-warning">Yesterday</span>'; } else {
} else if (matchDay.getTime() === todayDay.getTime()) { dateBadge = '<span class="badge bg-secondary">' + fixtureDate + '</span>';
dateBadge = '<span class="badge bg-success">Today</span>'; }
} else { } else {
dateBadge = '<span class="badge bg-secondary">' + fixtureDate + '</span>'; dateBadge = '<span class="badge bg-secondary">' + fixtureDate + '</span>';
} }
} else if (fixture.start_time) {
dateBadge = '<span class="badge bg-secondary">' + fixtureDate + '</span>';
} else { } else {
dateBadge = '<span class="badge bg-secondary">Not set</span>'; dateBadge = '<span class="badge bg-secondary">Not set</span>';
} }
......
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