How Would You Create a Transit Calendar Exercise?
From the earlier reference collection. Read the current software blog.
Practice deriving active service IDs for a date by evaluating weekday ranges and then applying date-specific exceptions.
Frame the exercise around one date
A transit calendar exercise teaches a compact but important data task: determine which service IDs are active on a selected date. Ask the learner to enter or choose a date, then print the resulting identifiers. The goal is a transparent calculation that can be checked by hand, not a full trip planner.
Use a small fixture with a few calendar rows and a handful of exceptions. Include a service range that covers the selected date, one that starts later, and weekday flags that distinguish the date. A carefully chosen fixture makes it possible to see which rule contributed each result.
Evaluate calendar rows
For every row in calendar.txt, check that the selected date is inside its inclusive start and end dates. Then select the weekday column for that date. Add the service ID to the active set only when both the date range and weekday flag permit service.
For instance, if the chosen date is a Saturday, a row with Saturday enabled can contribute its service ID, but only within its date range. A weekday-only row should not be active on that Saturday simply because the date falls between its boundaries. GTFS service days can have conventions that differ from ordinary calendar-day intuition, so keep this exercise focused on the date and calendar rules.
Apply date-specific exceptions
After building the base set, apply rows from calendar_dates.txt that match the selected date. An addition exception activates its service ID; a removal exception deactivates it. Applying exceptions after the base calculation lets a date-specific rule alter the normal weekday pattern.
Have the program report not only the final IDs but also a short reason for each change: base calendar, added for date, or removed for date. If an exception references a service ID not otherwise seen, display it and flag the unfamiliar ID for inspection rather than dropping it silently.
Turn the output into a learning check
A useful answer includes the input date, active service IDs in stable order, and a brief count. If the set is empty, say that no service IDs were active according to the supplied tables. This wording avoids claiming that no transit operates in the real world; the exercise only describes its fixture.
Finish with a few hand-check questions: Was the date in range? Which weekday flag applied? Did an exception add or remove service? The GTFS schedule reference provides the field definitions when preparing a more realistic fixture. As a follow-up, connect active service IDs to trips and list the trip IDs that use them.