Skip to content

Commit a303822

Browse files
committed
Handle GTFS with no calendar.txt
1 parent 6f3b693 commit a303822

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Updated
1111
- Update Dockerfile
1212

13+
### Fixed
14+
- Handle GTFS with no calendar.txt
15+
1316
## [2.11.1] - 2025-09-19
1417

1518
### Fixed

src/lib/formatters.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,7 @@ export function formatTimetableId({
270270
routeIds,
271271
directionId,
272272
days,
273+
dates,
273274
}: {
274275
routeIds: string[];
275276
directionId?: 0 | 1;
@@ -282,8 +283,16 @@ export function formatTimetableId({
282283
saturday?: null | 0 | 1;
283284
sunday?: null | 0 | 1;
284285
};
286+
dates?: number[];
285287
}) {
286-
let timetableId = `${routeIds.join('_')}|${calendarToCalendarCode(days)}`;
288+
let timetableId = routeIds.join('_');
289+
290+
if (calendarToCalendarCode(days)) {
291+
timetableId += `|${calendarToCalendarCode(days)}`;
292+
} else if (dates && dates.length > 0) {
293+
timetableId += `|${dates.join('_')}`;
294+
}
295+
287296
if (!isNullOrEmpty(directionId)) {
288297
timetableId += `|${directionId}`;
289298
}

src/lib/time-utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ export function calendarToCalendarCode(c: {
3232
saturday?: null | 0 | 1;
3333
sunday?: null | 0 | 1;
3434
}) {
35+
if (Object.values(c).every((value) => value === null)) {
36+
return '';
37+
}
38+
3539
return `${c.monday}${c.tuesday}${c.wednesday}${c.thursday}${c.friday}${c.saturday}${c.sunday}`;
3640
}
3741

src/lib/utils.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,23 @@ const createTimetable = ({
515515
...(calendarDates?.map((calendarDate) => calendarDate.service_id) ?? []),
516516
]);
517517

518-
const days = {};
518+
const days: {
519+
monday: null | 0 | 1;
520+
tuesday: null | 0 | 1;
521+
wednesday: null | 0 | 1;
522+
thursday: null | 0 | 1;
523+
friday: null | 0 | 1;
524+
saturday: null | 0 | 1;
525+
sunday: null | 0 | 1;
526+
} = {
527+
monday: null,
528+
tuesday: null,
529+
wednesday: null,
530+
thursday: null,
531+
friday: null,
532+
saturday: null,
533+
sunday: null,
534+
};
519535
let startDate: number | null = null;
520536
let endDate: number | null = null;
521537

@@ -543,6 +559,7 @@ const createTimetable = ({
543559
routeIds: [route.route_id],
544560
directionId: directionId,
545561
days: days,
562+
dates: calendarDates?.map((calendarDate) => calendarDate.date),
546563
});
547564

548565
return {
@@ -626,6 +643,10 @@ const convertRoutesToTimetablePages = (config: Config) => {
626643
}
627644
}
628645

646+
if (timetables.length === 0) {
647+
continue;
648+
}
649+
629650
if (config.groupTimetablesIntoPages === true) {
630651
timetablePages.push(
631652
createTimetablePage({

0 commit comments

Comments
 (0)