didier/functions/les.py

32 lines
1.1 KiB
Python
Raw Normal View History

2021-08-08 18:24:11 +02:00
from datetime import datetime, timedelta
from functions.timeFormatters import dateTimeNow, weekdayToInt, forward_to_weekday, skip_weekends
from typing import Optional
2021-08-08 18:24:11 +02:00
def find_target_date(arg: Optional[str]) -> datetime:
"""
2021-08-08 18:24:11 +02:00
Find the requested date out of the user's arguments
"""
2021-08-08 18:24:11 +02:00
# Start at current date
day: datetime = dateTimeNow()
2021-08-08 18:24:11 +02:00
# If no offset was provided, check the time
# otherwise the argument overrides it
if arg is None:
# When the command is used after 6 pm, show schedule
# for the next day instead
if day.hour > 18:
day += timedelta(days=1)
elif 0 <= (weekday := weekdayToInt(arg)) <= 4: # Weekday provided
day = forward_to_weekday(day, weekday)
elif arg.lower() == "morgen": # Tomorrow's schedule
day += timedelta(days=1)
elif arg.lower() == "overmorgen": # Day after tomorrow's schedule
day += timedelta(days=2)
2021-08-08 18:24:11 +02:00
# TODO show a different embed when "(over)morgen" is requested & it lands on a weekend
# Don't land on a weekend
day = skip_weekends(day)
2021-08-08 18:24:11 +02:00
return day