Fixed handling of event dates (for #2)
This commit is contained in:
@@ -106,7 +106,7 @@ class CogEvent(Cog):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not await validate_event_validity(ctx, name, start_date, end_date, guild_timezone):
|
if not await validate_event_validity(ctx, name, start_date, end_date, to_utc=True):
|
||||||
return
|
return
|
||||||
|
|
||||||
processed_media: List[Dict[str, Any]] = (
|
processed_media: List[Dict[str, Any]] = (
|
||||||
@@ -204,7 +204,12 @@ class CogEvent(Cog):
|
|||||||
start_date: datetime = (
|
start_date: datetime = (
|
||||||
pycord_event.starts if start is None else datetime.strptime(start, "%d.%m.%Y %H:%M")
|
pycord_event.starts if start is None else datetime.strptime(start, "%d.%m.%Y %H:%M")
|
||||||
)
|
)
|
||||||
start_date = start_date.replace(tzinfo=guild_timezone)
|
|
||||||
|
start_date = (
|
||||||
|
start_date.replace(tzinfo=ZoneInfo("UTC"))
|
||||||
|
if start is None
|
||||||
|
else start_date.replace(tzinfo=guild_timezone)
|
||||||
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# TODO Make a nice message
|
# TODO Make a nice message
|
||||||
await ctx.respond(
|
await ctx.respond(
|
||||||
@@ -216,7 +221,12 @@ class CogEvent(Cog):
|
|||||||
end_date: datetime = (
|
end_date: datetime = (
|
||||||
pycord_event.ends if end is None else datetime.strptime(end, "%d.%m.%Y %H:%M")
|
pycord_event.ends if end is None else datetime.strptime(end, "%d.%m.%Y %H:%M")
|
||||||
)
|
)
|
||||||
end_date = end_date.replace(tzinfo=guild_timezone)
|
|
||||||
|
end_date = (
|
||||||
|
end_date.replace(tzinfo=ZoneInfo("UTC"))
|
||||||
|
if end is None
|
||||||
|
else end_date.replace(tzinfo=guild_timezone)
|
||||||
|
)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# TODO Make a nice message
|
# TODO Make a nice message
|
||||||
await ctx.respond(
|
await ctx.respond(
|
||||||
@@ -224,7 +234,7 @@ class CogEvent(Cog):
|
|||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
||||||
if not await validate_event_validity(ctx, name, start_date, end_date, guild_timezone):
|
if not await validate_event_validity(ctx, name, start_date, end_date, to_utc=True):
|
||||||
return
|
return
|
||||||
|
|
||||||
processed_media: List[Dict[str, Any]] = (
|
processed_media: List[Dict[str, Any]] = (
|
||||||
|
@@ -14,20 +14,28 @@ async def validate_event_validity(
|
|||||||
ctx: ApplicationContext,
|
ctx: ApplicationContext,
|
||||||
name: str,
|
name: str,
|
||||||
start_date: datetime | None,
|
start_date: datetime | None,
|
||||||
finish_date: datetime | None,
|
end_date: datetime | None,
|
||||||
guild_timezone: ZoneInfo,
|
|
||||||
event_id: ObjectId | None = None,
|
event_id: ObjectId | None = None,
|
||||||
|
to_utc: bool = False,
|
||||||
) -> bool:
|
) -> bool:
|
||||||
if start_date >= finish_date:
|
start_date_internal: datetime = start_date.astimezone(ZoneInfo("UTC")) if to_utc else start_date
|
||||||
# TODO Make a nice message
|
end_date_internal: datetime = end_date.astimezone(ZoneInfo("UTC")) if to_utc else end_date
|
||||||
await ctx.respond("Start date must be before finish date")
|
|
||||||
return False
|
|
||||||
|
|
||||||
if start_date < datetime.now(tz=guild_timezone):
|
if start_date_internal < datetime.now(tz=ZoneInfo("UTC")):
|
||||||
# TODO Make a nice message
|
# TODO Make a nice message
|
||||||
await ctx.respond("Start date must not be in the past")
|
await ctx.respond("Start date must not be in the past")
|
||||||
return False
|
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.
|
# TODO Add validation for concurrent events.
|
||||||
# Only one event can take place at the same time.
|
# Only one event can take place at the same time.
|
||||||
query: Dict[str, Any] = {
|
query: Dict[str, Any] = {
|
||||||
|
Reference in New Issue
Block a user