Skip to content

A GTFS Trip Anchored at Midnight

  • 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 Trip Anchored at Midnight

A feed import adds each stop time to local midnight, and on the day the clocks go forward every stop of that service day shows an hour late.

The naive approach

// The naive approach: add the stop time to local midnight of the service day
import { parseGtfsTime } from "@northguild/gmt/rail/parse";
import { resolveLocal } from "@northguild/gmt/instant/convert";
import { addUtc } from "@northguild/gmt/utc/calculate";

const record = parseGtfsTime("08:00:00");
// { seconds: 28800, dayOverflow: 0 }

const midnight = resolveLocal("2026-03-29T00:00:00", "Europe/Berlin");
// "2026-03-28T23:00:00Z"

if (record !== null) addUtc(midnight, { days: record.dayOverflow, seconds: record.seconds });
// "2026-03-29T07:00:00Z" — 09:00 in Berlin

Watch it break

output 

Why

A GTFS time counts from noon minus 12 hours of the service day. On most days that is local midnight. On 29 March 2026 the clocks in Berlin go forward at 02:00, so noon minus 12 hours is 23:00 on 28 March, and a stop at 08:00:00 is 06:00 UTC, which reads 08:00 in Berlin. An import that adds the time to local midnight gets 07:00 UTC, which reads 09:00. Every stop of that service day shows an hour late, not only the ones after the change: 00:30:00 is 23:30 on 28 March under GTFS and 00:30 under a midnight anchor. Nothing in the stored value shows it, and the feed looks fine until the departure board and the trains disagree twice a year. In October the same import is an hour early, because the clocks go back and the day has an extra hour. gtfsToInstant takes the service date and the agency's zone and counts from the right point.

The gmt approach

import { gtfsToInstant } from "@northguild/gmt/rail/convert";

gtfsToInstant("20260329", "08:00:00", "Europe/Berlin");
// "2026-03-29T06:00:00Z" — 08:00 in Berlin

Same widget, working

output 

The fix is to count from noon minus 12 hours of the service day, in the agency’s zone. See Rail: GTFS Service Days for the rule, and Rail mistakes for the others that come with it.

Try it in the GTFS Service Day Clock.

© 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.