- def all(cls, db_conn: DatabaseConnection):
- """Return list of all Days in database."""
- days = []
- for row in db_conn.exec('SELECT * FROM days'):
- days += [cls.from_table_row(row)]
+ def with_filled_gaps(cls, days: list[Day], start_date: str, end_date: str
+ ) -> list[Day]:
+ """In days, fill with (un-saved) Days gaps between start/end_date."""
+ if start_date > end_date:
+ return days
+ days.sort()
+ if start_date not in [d.date for d in days]:
+ days[:] = [Day(start_date, init_empty_todo_list=True)] + days
+ if end_date not in [d.date for d in days]:
+ days += [Day(end_date, init_empty_todo_list=True)]
+ 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, init_empty_todo_list=True)
+ gapless_days += [day]
+ days[:] = gapless_days