Skip to content

A GTFS Time Folded into One Day

  • Public transport timetables in GTFS feeds, where a stop time runs past midnight and still belongs to the service day its trip began on.

A GTFS Time Folded into One Day

A night trip's last stop is written 25:35:00 in stop_times.txt. A feed import reads it as a clock time. What does it store?

The naive approach

// The naive approach: check it as a clock time, then fold the hour into a day
import { isValidTime } from "@northguild/gmt/plain/validate";

isValidTime("25:35:00");
// false — there is no 25th hour on a clock

const [hours, minutes, seconds] = "25:35:00".split(":");
const folded = [String(Number(hours) % 24).padStart(2, "0"), minutes, seconds].join(":");
// "01:35:00" — a time at the start of the service day

Watch it break

The naive approach silently produces wrong results — there is no GMT equivalent to demonstrate because the failure is not using GMT.

Why

A GTFS time counts from the start of the service day, so a trip that runs through midnight keeps counting: 25:35:00 is 1 day past the service day, 01:35:00, and still part of the same service day. An import that refuses the value loses the stop. An import that folds it keeps the stop and loses the day. The trip's stops after midnight now sort before its evening stops, and each one's time no longer says it is past midnight. Nothing in the stored value shows that anything was lost, which is why the feed looks fine until a rider asks for the last train. parseGtfsTime keeps the days past the service day in a number of their own, and formatGtfsTime writes the same text back.

The gmt approach

import { parseGtfsTime } from "@northguild/gmt/rail/parse";
import { formatGtfsTime } from "@northguild/gmt/rail/format";

const record = parseGtfsTime("25:35:00");
// { seconds: 5700, dayOverflow: 1 }

if (record !== null) formatGtfsTime(record);
// "25:35:00"

Same widget, working

output 

The fix is to keep the days past the service day. See Rail: GTFS Service Days for the rule, and Rail mistakes for the others that come with it.

Try it in the GTFS Time Reader.

© 2026 NorthGuild · Licences

Code examples: MIT-0. Packages: MIT. Third-party data and components: their own licences, credited where they appear. Everything else: © 2026 NorthGuild, all rights reserved.