Small bugfix in timezone printing

pull/169/head
Stijn De Clercq 2023-02-17 01:04:24 +01:00
parent c0adc55be2
commit 1af7e241e2
3 changed files with 12 additions and 3 deletions

View File

@ -47,4 +47,4 @@ async def get_events(session: AsyncSession, *, now: datetime.datetime) -> list[E
async def get_next_event(session: AsyncSession, *, now: datetime.datetime) -> Optional[Event]:
"""Get the first upcoming event"""
statement = select(Event).where(Event.timestamp > now).order_by(Event.timestamp)
return (await session.execute(statement)).scalar_one_or_none()
return (await session.execute(statement)).scalars().first()

View File

@ -19,7 +19,7 @@ from didier.utils.discord import colours
from didier.utils.discord.assets import get_author_avatar, get_user_avatar
from didier.utils.discord.constants import Limits
from didier.utils.timer import Timer
from didier.utils.types.datetime import str_to_date, tz_aware_now
from didier.utils.types.datetime import localize, str_to_date, tz_aware_now
from didier.utils.types.string import abbreviate, leading
from didier.views.modals import CreateBookmark
@ -63,7 +63,7 @@ class Discord(commands.Cog):
return await self.client.log_error(f"Unable to find event with id {event_id}", log_to_discord=True)
channel = self.client.get_channel(event.notification_channel)
human_readable_time = event.timestamp.strftime("%A, %B %d %Y - %H:%M")
human_readable_time = localize(event.timestamp).strftime("%A, %B %d %Y - %H:%M")
embed = discord.Embed(title=event.name, colour=discord.Colour.blue())
embed.set_author(name="Upcoming Event")

View File

@ -7,6 +7,7 @@ __all__ = [
"LOCAL_TIMEZONE",
"forward_to_next_weekday",
"int_to_weekday",
"localize",
"parse_dm_string",
"skip_weekends",
"str_to_date",
@ -42,6 +43,14 @@ def int_to_weekday(number: int) -> str: # pragma: no cover # it's useless to wr
return ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"][number]
def localize(dt_instance: datetime.datetime, *, default_timezone="UTC") -> datetime.datetime:
"""Localize a datetime instance to my local timezone"""
if dt_instance.tzinfo is None:
dt_instance = dt_instance.replace(tzinfo=zoneinfo.ZoneInfo(default_timezone))
return dt_instance.astimezone(LOCAL_TIMEZONE)
def parse_dm_string(argument: str) -> datetime.date:
"""Parse a string to [day]/[month]