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():
# Use the first match as the representative for the fixture
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
fixture_data = {
'id': first_match.id,
......@@ -4025,7 +4035,10 @@ def get_fixtures():
'created_at': first_match.created_at.isoformat(),
'fixture_status': fixture_status,
'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)
......
......@@ -363,23 +363,14 @@ function filterFixtures() {
const pastFilter = document.getElementById('past-filter').value;
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 => {
// Past fixtures filter
// Past fixtures filter - use server-provided is_past flag (venue timezone aware)
if (pastFilter === 'hide') {
// Hide past fixtures by default
if (fixture.start_time) {
const fixtureDate = new Date(fixture.start_time);
fixtureDate.setHours(0, 0, 0, 0);
if (fixtureDate < today) {
// Hide past fixtures by default - use server's is_past flag
if (fixture.is_past === true) {
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
// Upload filter - check the first match's upload status
......@@ -437,25 +428,27 @@ function renderFixturesTable(fixtures) {
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';
// Determine if this is yesterday, today, or other date
// Determine if this is yesterday, today, or other date using server-provided flags
let dateBadge = '';
if (fixture.start_time) {
const matchDate = new Date(fixture.start_time);
if (fixture.is_today === true) {
dateBadge = '<span class="badge bg-success">Today</span>';
} else if (fixture.is_past === true) {
// Check if it's yesterday (past but within 1 day)
if (fixture.fixture_venue_date) {
const venueDate = new Date(fixture.fixture_venue_date);
const today = new Date();
const yesterday = new Date(today);
yesterday.setDate(yesterday.getDate() - 1);
const matchDay = new Date(matchDate.getFullYear(), matchDate.getMonth(), matchDate.getDate());
const todayDay = new Date(today.getFullYear(), today.getMonth(), today.getDate());
const yesterdayDay = new Date(yesterday.getFullYear(), yesterday.getMonth(), yesterday.getDate());
if (matchDay.getTime() === yesterdayDay.getTime()) {
const diffTime = today.getTime() - venueDate.getTime();
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
if (diffDays === 1) {
dateBadge = '<span class="badge bg-warning">Yesterday</span>';
} else if (matchDay.getTime() === todayDay.getTime()) {
dateBadge = '<span class="badge bg-success">Today</span>';
} else {
dateBadge = '<span class="badge bg-secondary">' + fixtureDate + '</span>';
}
} else {
dateBadge = '<span class="badge bg-secondary">' + fixtureDate + '</span>';
}
} else if (fixture.start_time) {
dateBadge = '<span class="badge bg-secondary">' + fixtureDate + '</span>';
} else {
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