Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow events crossing years #208

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion events/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ start_date: July 10
end_date: July 20
```

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.
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.

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.

Expand Down
4 changes: 2 additions & 2 deletions events/new_year/meta.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
start_date: December 26
end_date: December 31
start_date: December 29
end_date: January 3
---
**New Year**

Expand Down
10 changes: 4 additions & 6 deletions events/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
We check that each event directory satisfies the following:
* Contains 'meta.md', `banners/` and 'server_icons/' with at least 1 file inside each
* The 'meta.md' file either registers the event as fallback, or specifies the start and end dates
* The end date must either be the same as the start date, or chronologically subsequent
* The 'meta.md' file contains an event description between 1 and 2048 characters in length

If all events are set up correctly, we also validate that:
Expand Down Expand Up @@ -123,8 +122,6 @@ def make_event(name: str, from_dir: Path) -> Event:
except Exception as exc:
raise Misconfiguration(f"Attribute 'end_date' with value '{end_date}' failed to parse: {exc}")

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

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

Expand All @@ -133,20 +130,21 @@ def active_days(event: Event) -> t.Iterator[date]:
"""
Generate all days in which `event` is active.

All dates returned will be in the same year.

This can only be called for non-fallback events. The fallback event does not have start and end dates.
"""
if None in (event.start_date, event.end_date):
raise RuntimeError("Cannot generate days: event does not have start and date!")

if not event.start_date <= event.end_date:
raise RuntimeError("Cannot generate days: start date does not precede end date!")

state = event.start_date
while True:
yield state
if state == event.end_date:
break
state += timedelta(days=1)
# Wrap around to the same year, so comparisons only compare day and month.
state = state.replace(year=ARBITRARY_YEAR)


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