Skip to content

Commit 6023c10

Browse files
committed
Allow events to cross from one year to another
This is the case if the end_date is before the start_date
1 parent b8824d8 commit 6023c10

1 file changed

Lines changed: 4 additions & 5 deletions

File tree

events/validation.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,6 @@ def make_event(name: str, from_dir: Path) -> Event:
123123
except Exception as exc:
124124
raise Misconfiguration(f"Attribute 'end_date' with value '{end_date}' failed to parse: {exc}")
125125

126-
if not start_date <= end_date:
127-
raise Misconfiguration("End date must be equal or subsequent to start date")
128126

129127
return Event(name=name, fallback=False, start_date=start_date, end_date=end_date, description=description)
130128

@@ -133,20 +131,21 @@ def active_days(event: Event) -> t.Iterator[date]:
133131
"""
134132
Generate all days in which `event` is active.
135133
134+
All dates returned will be in the same year.
135+
136136
This can only be called for non-fallback events. The fallback event does not have start and end dates.
137137
"""
138138
if None in (event.start_date, event.end_date):
139139
raise RuntimeError("Cannot generate days: event does not have start and date!")
140140

141-
if not event.start_date <= event.end_date:
142-
raise RuntimeError("Cannot generate days: start date does not precede end date!")
143-
144141
state = event.start_date
145142
while True:
146143
yield state
147144
if state == event.end_date:
148145
break
149146
state += timedelta(days=1)
147+
# Wrap around to the same year, so comparisons only compare day and month.
148+
state = state.replace(year=ARBITRARY_YEAR)
150149

151150

152151
def find_collisions(events: t.List[Event]) -> t.Dict[date, t.List[Event]]:

0 commit comments

Comments
 (0)