mirror of https://github.com/stijndcl/didier
Small bugfix in timezone printing
parent
c0adc55be2
commit
1af7e241e2
|
@ -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]:
|
async def get_next_event(session: AsyncSession, *, now: datetime.datetime) -> Optional[Event]:
|
||||||
"""Get the first upcoming event"""
|
"""Get the first upcoming event"""
|
||||||
statement = select(Event).where(Event.timestamp > now).order_by(Event.timestamp)
|
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()
|
||||||
|
|
|
@ -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.assets import get_author_avatar, get_user_avatar
|
||||||
from didier.utils.discord.constants import Limits
|
from didier.utils.discord.constants import Limits
|
||||||
from didier.utils.timer import Timer
|
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.utils.types.string import abbreviate, leading
|
||||||
from didier.views.modals import CreateBookmark
|
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)
|
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)
|
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 = discord.Embed(title=event.name, colour=discord.Colour.blue())
|
||||||
embed.set_author(name="Upcoming Event")
|
embed.set_author(name="Upcoming Event")
|
||||||
|
|
|
@ -7,6 +7,7 @@ __all__ = [
|
||||||
"LOCAL_TIMEZONE",
|
"LOCAL_TIMEZONE",
|
||||||
"forward_to_next_weekday",
|
"forward_to_next_weekday",
|
||||||
"int_to_weekday",
|
"int_to_weekday",
|
||||||
|
"localize",
|
||||||
"parse_dm_string",
|
"parse_dm_string",
|
||||||
"skip_weekends",
|
"skip_weekends",
|
||||||
"str_to_date",
|
"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]
|
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:
|
def parse_dm_string(argument: str) -> datetime.date:
|
||||||
"""Parse a string to [day]/[month]
|
"""Parse a string to [day]/[month]
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue