Skip to content

Instantly share code, notes, and snippets.

@derhuerst
Last active May 27, 2023 18:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save derhuerst/574edc94981a21ef0ce90713f1cff7f6 to your computer and use it in GitHub Desktop.
Save derhuerst/574edc94981a21ef0ce90713f1cff7f6 to your computer and use it in GitHub Desktop.
note about GTFS Time values

Note: An Issue has been opened in the Google Transit repo to clarify the meaning of stop_timezone & agency_timezone.


Time - Time in the HH:MM:SS format (H:MM:SS is also accepted). The time is measured from "noon minus 12h" of the service day (effectively midnight except for days on which daylight savings time changes occur). For times occurring after midnight, enter the time as a value greater than 24:00:00 in HH:MM:SS local time for the day on which the trip schedule begins. Example: 14:30:00 for 2:30PM or 25:35:00 for 1:35AM on the next day.

GTFS field types

Fun fact: if your transit system has a bus starting at 00:30:00 local wall time, then the only proper way I know to encode such bus in GTFS (static) is by defining it as 24:30:00 of the previous day. It is otherwise impossible to encode this bus on a day when time is moved back by 1 hour (that is, the calendar day, when 13 hours pass between 00:00 wall time and 12:00 wall time) -- GTFS definition of time is 12 hours before local noon, which corresponds to 1am wall time for that day, and you'd need negative time to encode such a trip at such a day; GTFS 00:30:00 means wall time 01:30:00 on such day (assuming a typical switch-over time between 2am and 4am). In the same way on the short day (moving time forward), GTFS 00:30:00 will correspond to 23:30:00 wall time of the previous day.

If I were to give a recommendation, I'd recommend to always provide times in GTFS (static) feeds in the time window of 03:00:00-27:00:00 (or 02:00:00-26:00:00, depending on when the typical DST-switchover happens in the system), because these times correspond to wall times on every day of the year.

– google/transit#15

As long as the DST <-> standard time switches happen before noon in every involved locale & timezone, GTFS Time values are monotonically increasing.

Examples

2019-10-27 with CEST

ISO 8601 UNIX epoch wall clock time GTFS value
2019-10-27T01:00:00+02:00 1572130800 01:00:00 00:00:00
2019-10-27T01:59:59+02:00 1572134399 01:59:59 00:59:59
2019-10-27T02:59:59+02:00 1572137999 02:59:59 01:59:59
2019-10-27T02:00:00+01:00 1572138000 02:00:00 02:00:00
2019-10-27T02:59:59+01:00 1572141599 02:59:59 02:59:59
2019-10-27T03:00:00+01:00 1572141600 03:00:00 03:00:00

2019-03-31 with CEST

ISO 8601 UNIX epoch wall clock time GTFS value
2019-03-31T01:00:00+01:00 1553990400 01:00:00 02:00:00
2019-03-31T01:59:59+01:00 1553993999 01:59:59 02:59:59
2019-03-31T03:00:00+02:00 1553994000 03:00:00 03:00:00
@lenaschimmel
Copy link

Do you know if GTFS time values can be negative, i.e. -00:05:00? The documentation explicitly states that values larger than 24:00:00 are possible, but there's no explicit min value.

Even if no GTFS schedule would ever use a negative time, I think those could occur when working with delays.

For example, a vehicle might be scheduled for departure at 00:02:00 and if this vehicle is found to have a delay of -5 minutes / -300 seconds, the actual departure could be -00:03:00. If this was not allowed, conversion to 23:57:00 (or one hour later/earlier when daylight saving switches) would be needed, as well as changing the date one day back. The latter seems to be problematic as well, given that a tuple of trip_id, trip_start_date and ideally trip_start_time is often used to identify a specific instance of a trip.

@derhuerst
Copy link
Author

Even if no GTFS schedule would ever use a negative time, I think those could occur when working with delays.

What does the use case look like? When would you want to express delayed vehicles in GTFS Static? GTFS Realtime uses unix timestamps (as in seconds since the Unix epoch) to express absolute points in time, and therefore does not have the properties described in the Gist above.

Do you know if GTFS time values can be negative, i.e. -00:05:00?

I don't know, you'll have to clarify in the GTFS issue tracker.

The latter seems to be problematic as well, given that a tuple of trip_id, trip_start_date and ideally trip_start_time is often used to identify a specific instance of a trip.

Yes, I made that observation as well. Using these as an ID is problematic for various reasons.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment