fix: convert match local time to UTC in isLive()

setHours() used the server's local timezone, so "15:00 UTC-5" on a UTC server
was treated as 15:00 UTC instead of 20:00 UTC — causing wrong live detection.

Now parses the UTC offset from the time string and converts to actual UTC
kickoff before comparing: UTC = local_time - offset (15:00 UTC-5 = 20:00 UTC).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-14 17:24:59 +02:00
parent 42019e5035
commit 78340bd2db
+10 -8
View File
@@ -15,15 +15,17 @@ async function getTeamById(id: number) {
function isLive(dateStr: string | null, timeStr: string | null): boolean { function isLive(dateStr: string | null, timeStr: string | null): boolean {
if (!dateStr) return false if (!dateStr) return false
const now = new Date() const now = new Date()
const today = now.toISOString().slice(0, 10) if (now.toISOString().slice(0, 10) !== dateStr) return false
if (dateStr !== today) return false
if (!timeStr) return true if (!timeStr) return true
// parse time like "20:00 CET" or "13:00 UTC-6" // Parse "15:00 UTC-5" → convert to UTC kickoff time
const timePart = timeStr.split(' ')[0] const m = timeStr.match(/^(\d{1,2}):(\d{2})(?:\s*UTC([+-]\d+(?:\.\d+)?))?/)
const [h, m] = timePart.split(':').map(Number) if (!m) return true
if (isNaN(h)) return true const localH = parseInt(m[1])
const kickoff = new Date(now) const localMin = parseInt(m[2])
kickoff.setHours(h, m ?? 0, 0, 0) const tzOffset = m[3] ? parseFloat(m[3]) : 0 // e.g. -5 for UTC-5
// UTC = local time - tz offset (15:00 UTC-5 → 15:00 - (-5h) = 20:00 UTC)
const kickoff = new Date(`${dateStr}T00:00:00Z`)
kickoff.setUTCMinutes(kickoff.getUTCMinutes() + localH * 60 + localMin - tzOffset * 60)
const diffMin = (now.getTime() - kickoff.getTime()) / 60000 const diffMin = (now.getTime() - kickoff.getTime()) / 60000
return diffMin >= -5 && diffMin <= 125 return diffMin >= -5 && diffMin <= 125
} }