for row in db_conn.exec(sql, (start_date, end_date)):
days += [cls.by_id(db_conn, row[0])]
days.sort()
- if fill_gaps and len(days) > 1:
- gapless_days = []
- for i, day in enumerate(days):
- gapless_days += [day]
- if i < len(days) - 1:
- while day.next_date != days[i+1].date:
- day = Day(day.next_date)
- gapless_days += [day]
- days = gapless_days
+ if fill_gaps:
+ if start_date not in [d.date for d in days]:
+ days = [Day(start_date)] + days
+ if end_date not in [d.date for d in days]:
+ days += [Day(end_date)]
+ if len(days) > 1:
+ gapless_days = []
+ for i, day in enumerate(days):
+ gapless_days += [day]
+ if i < len(days) - 1:
+ while day.next_date != days[i+1].date:
+ day = Day(day.next_date)
+ gapless_days += [day]
+ days = gapless_days
return days
@property