Fixed handling of event dates (for #2)

This commit is contained in:
2025-05-02 12:20:24 +02:00
parent 80eae3f1b1
commit 5507295b1b
2 changed files with 29 additions and 11 deletions

View File

@@ -14,20 +14,28 @@ async def validate_event_validity(
ctx: ApplicationContext,
name: str,
start_date: datetime | None,
finish_date: datetime | None,
guild_timezone: ZoneInfo,
end_date: datetime | None,
event_id: ObjectId | None = None,
to_utc: bool = False,
) -> bool:
if start_date >= finish_date:
# TODO Make a nice message
await ctx.respond("Start date must be before finish date")
return False
start_date_internal: datetime = start_date.astimezone(ZoneInfo("UTC")) if to_utc else start_date
end_date_internal: datetime = end_date.astimezone(ZoneInfo("UTC")) if to_utc else end_date
if start_date < datetime.now(tz=guild_timezone):
if start_date_internal < datetime.now(tz=ZoneInfo("UTC")):
# TODO Make a nice message
await ctx.respond("Start date must not be in the past")
return False
if end_date_internal < datetime.now(tz=ZoneInfo("UTC")):
# TODO Make a nice message
await ctx.respond("End date must not be in the past")
return False
if start_date_internal >= end_date_internal:
# TODO Make a nice message
await ctx.respond("Start date must be before end date")
return False
# TODO Add validation for concurrent events.
# Only one event can take place at the same time.
query: Dict[str, Any] = {