From edafc35b8b46e86b446df9b90a2754fc876da884 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Thu, 30 May 2024 07:15:53 +0200 Subject: [PATCH] In calendar day gap filling, ensure days before and after existing days. --- plomtask/days.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) 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 -- 2.30.2