diff --git a/app/page.tsx b/app/page.tsx index 1bc46d2..258c4f3 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -53,8 +53,34 @@ interface UpcomingMatch { team2: { name: string; iso2?: string | null } } +function formatKickoff(date: string | null | undefined, time: string | null | undefined): string { + if (!date) return '' + const today = new Date() + const tomorrow = new Date(today); tomorrow.setDate(today.getDate() + 1) + const matchDate = new Date(date + 'T00:00:00') + const isToday = matchDate.toDateString() === today.toDateString() + const isTomorrow = matchDate.toDateString() === tomorrow.toDateString() + const dayLabel = isToday ? 'Today' : isTomorrow ? 'Tomorrow' + : matchDate.toLocaleDateString('en-GB', { weekday: 'short', day: 'numeric', month: 'short' }) + + if (!time) return dayLabel + + // Parse "HH:MM UTC±N" and convert to viewer's local time + const m = time.match(/^(\d{2}):(\d{2})(?:\s+UTC([+-]\d+(?:\.\d+)?))?/) + if (!m) return dayLabel + const h = parseInt(m[1]), min = parseInt(m[2]) + const offsetH = m[3] ? parseFloat(m[3]) : 0 + const utcMs = Date.UTC( + matchDate.getFullYear(), matchDate.getMonth(), matchDate.getDate(), + h - offsetH, min + ) + const local = new Date(utcMs) + const localTime = local.toLocaleTimeString('en-GB', { hour: '2-digit', minute: '2-digit' }) + return `${dayLabel} · ${localTime}` +} + function UpcomingFixture({ match }: { match: UpcomingMatch }) { - const time = match.time?.split(' ')[0] ?? '' + const label = formatKickoff(match.date, match.time) return (