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:
@@ -15,15 +15,17 @@ async function getTeamById(id: number) {
|
||||
function isLive(dateStr: string | null, timeStr: string | null): boolean {
|
||||
if (!dateStr) return false
|
||||
const now = new Date()
|
||||
const today = now.toISOString().slice(0, 10)
|
||||
if (dateStr !== today) return false
|
||||
if (now.toISOString().slice(0, 10) !== dateStr) return false
|
||||
if (!timeStr) return true
|
||||
// parse time like "20:00 CET" or "13:00 UTC-6"
|
||||
const timePart = timeStr.split(' ')[0]
|
||||
const [h, m] = timePart.split(':').map(Number)
|
||||
if (isNaN(h)) return true
|
||||
const kickoff = new Date(now)
|
||||
kickoff.setHours(h, m ?? 0, 0, 0)
|
||||
// Parse "15:00 UTC-5" → convert to UTC kickoff time
|
||||
const m = timeStr.match(/^(\d{1,2}):(\d{2})(?:\s*UTC([+-]\d+(?:\.\d+)?))?/)
|
||||
if (!m) return true
|
||||
const localH = parseInt(m[1])
|
||||
const localMin = parseInt(m[2])
|
||||
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
|
||||
return diffMin >= -5 && diffMin <= 125
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user