From 133db456a4bd069daecb60b3ec6fa147868493a3 Mon Sep 17 00:00:00 2001
From: Copilot <198982749+Copilot@users.noreply.github.com>
Date: Tue, 18 Nov 2025 00:27:51 +0100
Subject: Handle GTFS times exceeding 24 hours for night services (#98)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: arielcostas <94913521+arielcostas@users.noreply.github.com>
Co-authored-by: Ariel Costas Guerrero <ariel@costas.dev>
---
 src/frontend/app/routes/timetable-$id.tsx | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

(limited to 'src/frontend/app/routes/timetable-$id.tsx')

diff --git a/src/frontend/app/routes/timetable-$id.tsx b/src/frontend/app/routes/timetable-$id.tsx
index af5e42a..8a1cba7 100644
--- a/src/frontend/app/routes/timetable-$id.tsx
+++ b/src/frontend/app/routes/timetable-$id.tsx
@@ -38,9 +38,9 @@ const loadTimetableData = async (
   // Add delay to see skeletons in action (remove in production)
   await new Promise((resolve) => setTimeout(resolve, 1000));
 
-  const today = new Date().toISOString().split("T")[0]; // YYYY-MM-DD format
+  // Use "today" to let server determine date based on Europe/Madrid timezone
   const resp = await fetch(
-    `${regionConfig.timetableEndpoint}?date=${today}&stopId=${stopId}`,
+    `${regionConfig.timetableEndpoint}?date=today&stopId=${stopId}`,
     {
       headers: {
         Accept: "application/json",
@@ -61,6 +61,13 @@ const timeToMinutes = (time: string): number => {
   return hours * 60 + minutes;
 };
 
+// Utility function to format GTFS time for display (handle hours >= 24)
+const formatTimeForDisplay = (time: string): string => {
+  const [hours, minutes] = time.split(":").map(Number);
+  const normalizedHours = hours % 24;
+  return `${normalizedHours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}`;
+};
+
 // Filter past entries (keep only a few recent past ones)
 const filterTimetableData = (
   data: ScheduledTable[],
@@ -402,7 +409,7 @@ const TimetableTableWithScroll: React.FC<{
 
                 <div className="time-info">
                   <span className="departure-time">
-                    {entry.calling_time.slice(0, 5)}
+                    {formatTimeForDisplay(entry.calling_time)}
                   </span>
                   <div className="service-id">
                     {parseServiceId(entry.service_id)}
-- 
cgit v1.3

