Dev Helpers
← Back

Timetable clock display

Place this file at app/trains/page.tsx in an App Router project.

Open this example in the interactive library

Source code

// app/trains/page.tsx

export default function TimetableClockDisplay() {
  const trains = [
    { id: "A1", to: "Union", min: 510, track: 2, delay: 4 },
    { id: "B4", to: "West", min: 560, track: 1, delay: 0 },
    { id: "A2", to: "Union", min: 600, track: 2, delay: 12 },
  ];
  const clock = (n: number) =>
    String(Math.floor(n / 60)).padStart(2, "0") + ":" + String(n % 60).padStart(2, "0");
  return (
    <ul>
      {trains.map((t) => (
        <li key={t.id}>
          {t.to}: <del hidden={!t.delay}>{clock(t.min)}</del> {clock(t.min + t.delay)}
        </li>
      ))}
    </ul>
  );
}