mirror of https://github.com/stijndcl/didier
Compare commits
No commits in common. "41b5efd12d6ee6c44ad15f9e2758299e98695433" and "09dbe61dfe7fbc88f1560cc902db931fa985b2f2" have entirely different histories.
41b5efd12d
...
09dbe61dfe
|
|
@ -16,7 +16,7 @@ from didier.exceptions import HTTPException, NotInMainGuildException
|
||||||
from didier.utils.discord.converters.time import DateTransformer
|
from didier.utils.discord.converters.time import DateTransformer
|
||||||
from didier.utils.discord.flags.school import StudyGuideFlags
|
from didier.utils.discord.flags.school import StudyGuideFlags
|
||||||
from didier.utils.discord.users import to_main_guild_member
|
from didier.utils.discord.users import to_main_guild_member
|
||||||
from didier.utils.types.datetime import skip_weekends, tz_aware_today
|
from didier.utils.types.datetime import skip_weekends
|
||||||
|
|
||||||
|
|
||||||
class School(commands.Cog):
|
class School(commands.Cog):
|
||||||
|
|
@ -49,7 +49,7 @@ class School(commands.Cog):
|
||||||
"""
|
"""
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
if day_dt is None:
|
if day_dt is None:
|
||||||
day_dt = tz_aware_today()
|
day_dt = date.today()
|
||||||
|
|
||||||
day_dt = skip_weekends(day_dt)
|
day_dt = skip_weekends(day_dt)
|
||||||
|
|
||||||
|
|
@ -78,7 +78,7 @@ class School(commands.Cog):
|
||||||
Menus are shown in Dutch by default, as a lot of dishes have very weird translations.
|
Menus are shown in Dutch by default, as a lot of dishes have very weird translations.
|
||||||
"""
|
"""
|
||||||
if day_dt is None:
|
if day_dt is None:
|
||||||
day_dt = tz_aware_today()
|
day_dt = date.today()
|
||||||
|
|
||||||
async with ctx.typing():
|
async with ctx.typing():
|
||||||
try:
|
try:
|
||||||
|
|
|
||||||
|
|
@ -18,12 +18,7 @@ from database.crud.ufora_courses import get_course_by_code
|
||||||
from database.schemas import UforaCourse
|
from database.schemas import UforaCourse
|
||||||
from didier.data.embeds.base import EmbedBaseModel
|
from didier.data.embeds.base import EmbedBaseModel
|
||||||
from didier.utils.discord import colours
|
from didier.utils.discord import colours
|
||||||
from didier.utils.types.datetime import (
|
from didier.utils.types.datetime import LOCAL_TIMEZONE, int_to_weekday, time_string
|
||||||
LOCAL_TIMEZONE,
|
|
||||||
int_to_weekday,
|
|
||||||
time_string,
|
|
||||||
tz_aware_today,
|
|
||||||
)
|
|
||||||
from didier.utils.types.string import leading
|
from didier.utils.types.string import leading
|
||||||
from settings import ScheduleType
|
from settings import ScheduleType
|
||||||
|
|
||||||
|
|
@ -76,7 +71,7 @@ class Schedule(EmbedBaseModel):
|
||||||
|
|
||||||
@overrides
|
@overrides
|
||||||
def to_embed(self, **kwargs) -> discord.Embed:
|
def to_embed(self, **kwargs) -> discord.Embed:
|
||||||
day: date = kwargs.get("day", tz_aware_today())
|
day: date = kwargs.get("day", date.today())
|
||||||
day_str = f"{leading('0', str(day.day))}/{leading('0', str(day.month))}/{leading('0', str(day.year))}"
|
day_str = f"{leading('0', str(day.day))}/{leading('0', str(day.month))}/{leading('0', str(day.year))}"
|
||||||
|
|
||||||
embed = discord.Embed(title=f"Schedule - {int_to_weekday(day.weekday())} {day_str}")
|
embed = discord.Embed(title=f"Schedule - {int_to_weekday(day.weekday())} {day_str}")
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ from didier.utils.types.datetime import (
|
||||||
forward_to_next_weekday,
|
forward_to_next_weekday,
|
||||||
parse_dm_string,
|
parse_dm_string,
|
||||||
str_to_weekday,
|
str_to_weekday,
|
||||||
tz_aware_today,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
__all__ = ["date_converter", "DateTransformer"]
|
__all__ = ["date_converter", "DateTransformer"]
|
||||||
|
|
@ -26,7 +25,7 @@ def date_converter(argument: Optional[str]) -> date:
|
||||||
|
|
||||||
# Default to today
|
# Default to today
|
||||||
if not argument:
|
if not argument:
|
||||||
return tz_aware_today()
|
return date.today()
|
||||||
|
|
||||||
argument = argument.lower()
|
argument = argument.lower()
|
||||||
|
|
||||||
|
|
@ -36,15 +35,15 @@ def date_converter(argument: Optional[str]) -> date:
|
||||||
"tmrw",
|
"tmrw",
|
||||||
"morgen",
|
"morgen",
|
||||||
):
|
):
|
||||||
return tz_aware_today() + timedelta(days=1)
|
return date.today() + timedelta(days=1)
|
||||||
|
|
||||||
if argument in ("overmorgen",):
|
if argument in ("overmorgen",):
|
||||||
return tz_aware_today() + timedelta(days=2)
|
return date.today() + timedelta(days=2)
|
||||||
|
|
||||||
# Weekdays passed in words
|
# Weekdays passed in words
|
||||||
with contextlib.suppress(ValueError):
|
with contextlib.suppress(ValueError):
|
||||||
weekday = str_to_weekday(argument)
|
weekday = str_to_weekday(argument)
|
||||||
return forward_to_next_weekday(tz_aware_today(), weekday, allow_today=False)
|
return forward_to_next_weekday(date.today(), weekday, allow_today=False)
|
||||||
|
|
||||||
# Date strings
|
# Date strings
|
||||||
with contextlib.suppress(ValueError):
|
with contextlib.suppress(ValueError):
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ __all__ = [
|
||||||
"str_to_weekday",
|
"str_to_weekday",
|
||||||
"time_string",
|
"time_string",
|
||||||
"tz_aware_now",
|
"tz_aware_now",
|
||||||
"tz_aware_today",
|
|
||||||
]
|
]
|
||||||
|
|
||||||
DateType = TypeVar("DateType", datetime.date, datetime.datetime)
|
DateType = TypeVar("DateType", datetime.date, datetime.datetime)
|
||||||
|
|
@ -56,7 +55,7 @@ def parse_dm_string(argument: str) -> datetime.date:
|
||||||
- [English Month, possibly abbreviated] DD
|
- [English Month, possibly abbreviated] DD
|
||||||
"""
|
"""
|
||||||
argument = argument.lower()
|
argument = argument.lower()
|
||||||
today = tz_aware_today()
|
today = datetime.date.today()
|
||||||
|
|
||||||
# DD/MM
|
# DD/MM
|
||||||
if "/" in argument:
|
if "/" in argument:
|
||||||
|
|
@ -188,8 +187,3 @@ def time_string(dt_instance: datetime.datetime) -> str:
|
||||||
def tz_aware_now() -> datetime.datetime:
|
def tz_aware_now() -> datetime.datetime:
|
||||||
"""Get the current date & time, but timezone-aware"""
|
"""Get the current date & time, but timezone-aware"""
|
||||||
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).astimezone(LOCAL_TIMEZONE)
|
return datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).astimezone(LOCAL_TIMEZONE)
|
||||||
|
|
||||||
|
|
||||||
def tz_aware_today() -> datetime.date:
|
|
||||||
"""Get the current day, but timezone-aware"""
|
|
||||||
return tz_aware_now().date()
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue