- def __init__(self, date: str):
- self.date = date
- self.datetime = date_valid(self.date)
- if not self.datetime:
- raise HandledException(f'Given date of wrong format: {self.date}')
+ On fill_gaps=True, will instantiate (without saving) Days of all dates
+ within the date range that don't exist yet.
+ """
+ min_date = '2024-01-01'
+ max_date = '2030-12-31'
+ start_date = valid_date(date_range[0] if date_range[0] else min_date)
+ end_date = valid_date(date_range[1] if date_range[1] else max_date)
+ days = []
+ sql = 'SELECT id FROM days WHERE id >= ? AND id <= ?'
+ 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
+ return days