Move get_datetime into own file.
Add test cases to cover get_datetime usage and edge cases.
This commit is contained in:
+1
-26
@@ -1,6 +1,5 @@
|
||||
"""File contains util functions."""
|
||||
|
||||
import calendar
|
||||
import os
|
||||
from collections.abc import Sequence
|
||||
from datetime import UTC, datetime
|
||||
@@ -22,6 +21,7 @@ from dakiny_bot.database.sql_data_classes import (
|
||||
)
|
||||
|
||||
from .dakiny_settings import settings
|
||||
from .election_utils import get_datetime
|
||||
|
||||
NOMINEE_SPLITTER = "========================================\n\n"
|
||||
REPO_DIR = "./dakiny-messages"
|
||||
@@ -34,31 +34,6 @@ VoteType = StrEnum("VoteType", ["COUNCIL", "DISCORDMANAGER", "CLANLEADER"])
|
||||
PointType = StrEnum("PointType", ["CLAN", "EVENT"])
|
||||
|
||||
|
||||
def get_datetime(month_day: str) -> datetime:
|
||||
"""
|
||||
Takes in a string month and day and returns a datetime object of that Month/Day this year.
|
||||
|
||||
Args:
|
||||
month_day (str): Month/Day in that format.
|
||||
|
||||
Returns:
|
||||
datetime: Datetime representation of Month/Day.
|
||||
"""
|
||||
today = datetime.now(tz=UTC).date()
|
||||
year = today.year
|
||||
month = int(month_day.split("/")[0])
|
||||
day = int(month_day.split("/")[1])
|
||||
|
||||
# ensure that year rolls over if current month is December and the next month is less than 12.
|
||||
if today.month == calendar.DECEMBER and month < calendar.OCTOBER:
|
||||
year += 1
|
||||
|
||||
if today.month == calendar.JANUARY and month > calendar.MARCH:
|
||||
year -= 1
|
||||
|
||||
return datetime(year, month, day, tzinfo=UTC)
|
||||
|
||||
|
||||
def get_election_name() -> str:
|
||||
"""
|
||||
Builds the unique name of the current election cycle.
|
||||
|
||||
Reference in New Issue
Block a user