Skip to content

Commit 8608bc3

Browse files
authored
Merge pull request #208 from python-discord/allow-events-crossing-years
Allow events crossing years
2 parents b8824d8 + 3151bf7 commit 8608bc3

3 files changed

Lines changed: 7 additions & 9 deletions

File tree

events/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ start_date: July 10
2323
end_date: July 20
2424
```
2525
26-
There must be exactly 1 fallback event, and 0 or more non-fallback events. Events cannot collide in time, and the end date must either be equal to the start date (1 day event) or chronologically subsequent. Both bounds are inclusive, and the format shown in the example above must be followed.
26+
There must be exactly 1 fallback event, and 0 or more non-fallback events. For single-day events, `end_date` must be equal to `start_date`. If `start_date` is a later day in the year than `end_date`, the event is interpreted as starting in one year and ending in the next. Both bounds are inclusive, and the format shown in the example above must be followed.
2727

2828
The markdown section of the meta file then contains the event's description. Descriptions are made available directly in the Discord guild as embeds sent by the Python bot. For formatting, use Discord's watered down Markdown ~ keep in mind that e.g. the `#` symbol does not create a heading.
2929

events/new_year/meta.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
start_date: December 26
3-
end_date: December 31
2+
start_date: December 29
3+
end_date: January 3
44
---
55
**New Year**
66

events/validation.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
We check that each event directory satisfies the following:
1010
* Contains 'meta.md', `banners/` and 'server_icons/' with at least 1 file inside each
1111
* The 'meta.md' file either registers the event as fallback, or specifies the start and end dates
12-
* The end date must either be the same as the start date, or chronologically subsequent
1312
* The 'meta.md' file contains an event description between 1 and 2048 characters in length
1413
1514
If all events are set up correctly, we also validate that:
@@ -123,8 +122,6 @@ def make_event(name: str, from_dir: Path) -> Event:
123122
except Exception as exc:
124123
raise Misconfiguration(f"Attribute 'end_date' with value '{end_date}' failed to parse: {exc}")
125124

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

129126
return Event(name=name, fallback=False, start_date=start_date, end_date=end_date, description=description)
130127

@@ -133,20 +130,21 @@ def active_days(event: Event) -> t.Iterator[date]:
133130
"""
134131
Generate all days in which `event` is active.
135132
133+
All dates returned will be in the same year.
134+
136135
This can only be called for non-fallback events. The fallback event does not have start and end dates.
137136
"""
138137
if None in (event.start_date, event.end_date):
139138
raise RuntimeError("Cannot generate days: event does not have start and date!")
140139

141-
if not event.start_date <= event.end_date:
142-
raise RuntimeError("Cannot generate days: start date does not precede end date!")
143-
144140
state = event.start_date
145141
while True:
146142
yield state
147143
if state == event.end_date:
148144
break
149145
state += timedelta(days=1)
146+
# Wrap around to the same year, so comparisons only compare day and month.
147+
state = state.replace(year=ARBITRARY_YEAR)
150148

151149

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

0 commit comments

Comments
 (0)