diff --git a/src/agenda_culturel/calendar.py b/src/agenda_culturel/calendar.py index 0485dcb..4db3056 100644 --- a/src/agenda_culturel/calendar.py +++ b/src/agenda_culturel/calendar.py @@ -19,7 +19,7 @@ def daterange(start, end, step=timedelta(1)): class DayInCalendar: - midnight = time(23, 59, 59) + midnight = time(0, 0, 0) def __init__(self, d, on_requested_interval=True): self.date = d @@ -74,15 +74,29 @@ class DayInCalendar: def _add_event_internal(self, event): from .models import Category + from copy import deepcopy + # copy event + local_event = deepcopy(event) - self.events.append(event) - if event.category is None: + # set values + if local_event.start_day != self.date: + local_event.start_day = self.date + local_event.start_time = None + if local_event.end_day != self.date: + local_event.end_day = None + local_event.end_time = None + + # add event to the day + self.events.append(local_event) + + # add in its category + if local_event.category is None: cat = Category.default_name else: - cat = event.category.name + cat = local_event.category.name if cat not in self.events_by_category: self.events_by_category[cat] = [] - self.events_by_category[cat].append(event) + self.events_by_category[cat].append(local_event) def filter_events(self): self.events.sort(