Skip to content
This repository has been archived by the owner on Nov 30, 2023. It is now read-only.

Fix for truncating periods with undefined date range. Fixes #413 #414

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,8 +1182,10 @@ def TruncatePeriod(service_period, start, end):
start: The start date as a string in YYYYMMDD format.
end: The end date as a string in YYYYMMDD format.
"""
service_period.start_date = max(service_period.start_date, start)
service_period.end_date = min(service_period.end_date, end)
if service_period.start_date is not None:
service_period.start_date = max(service_period.start_date, start)
if service_period.end_date is not None:
service_period.end_date = min(service_period.end_date, end)
dates_to_delete = []
for k in service_period.date_exceptions:
if (k < start) or (k > end):
Expand All @@ -1200,7 +1202,7 @@ def TruncatePeriod(service_period, start, end):
before = (cutoff_date - one_day_delta).strftime('%Y%m%d')

for a in self.feed_merger.a_schedule.GetServicePeriodList():
TruncatePeriod(a, 0, before)
TruncatePeriod(a, '0'*8, before)
for b in self.feed_merger.b_schedule.GetServicePeriodList():
TruncatePeriod(b, cutoff, '9'*8)

Expand Down
4 changes: 2 additions & 2 deletions tests/data/good_feed/calendar.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
FULLW,1,1,1,1,1,1,1,20070101,20151231
WE,0,0,0,0,0,1,1,20070101,20151231
FULLW,1,1,1,1,1,1,1,20070101,20251231
WE,0,0,0,0,0,1,1,20070101,20251231
4 changes: 2 additions & 2 deletions tests/data/googletransit/good_feed/calendar.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
service_id,monday,tuesday,wednesday,thursday,friday,saturday,sunday,start_date,end_date
FULLW,1,1,1,1,1,1,1,20070101,20151231
WE,0,0,0,0,0,1,1,20070101,20151231
FULLW,1,1,1,1,1,1,1,20070101,20251231
WE,0,0,0,0,0,1,1,20070101,20251231