diff --git a/lib/graphql/resolvers/index.ts b/lib/graphql/resolvers/index.ts index 7d9ceff..bad88d7 100644 --- a/lib/graphql/resolvers/index.ts +++ b/lib/graphql/resolvers/index.ts @@ -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 }