home · contact · privacy
In calendar day gap filling, ensure days before and after existing days.
authorChristian Heller <c.heller@plomlompom.de>
Thu, 30 May 2024 05:15:53 +0000 (07:15 +0200)
committerChristian Heller <c.heller@plomlompom.de>
Thu, 30 May 2024 05:15:53 +0000 (07:15 +0200)
plomtask/days.py

index fe1ba44e80e9a1c4182130b870d6d531dc9c9c06..e3d56d7fb1049c161b146af555b05ccf2ed2f904 100644 (file)
@@ -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