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

Commit

Permalink
Fix for truncating periods with undefined date range. Fixes #413
Browse files Browse the repository at this point in the history
max(0, None) resulted in start_date being set to 0 (integer). This crashed at a later point
when trying to parse the date string 0 (int).
Now explicitly handling None when truncating.
  • Loading branch information
askogvold committed May 5, 2016
1 parent 23e9537 commit 66320c5
Showing 1 changed file with 5 additions and 3 deletions.
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

0 comments on commit 66320c5

Please sign in to comment.