From: Christian Heller Date: Thu, 30 May 2024 05:15:53 +0000 (+0200) Subject: In calendar day gap filling, ensure days before and after existing days. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/decks/%7B%7Bprefix%7D%7D/ledger2?a=commitdiff_plain;h=edafc35b8b46e86b446df9b90a2754fc876da884;p=plomtask In calendar day gap filling, ensure days before and after existing days. --- diff --git a/plomtask/days.py b/plomtask/days.py index fe1ba44..e3d56d7 100644 --- a/plomtask/days.py +++ b/plomtask/days.py @@ -63,15 +63,20 @@ class Day(BaseModel[str]): 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