Move get_datetime into own file.

Add test cases to cover get_datetime usage and edge cases.
This commit is contained in:
2025-04-24 09:27:05 -04:00
parent af3b8e9e69
commit def9c4aa79
4 changed files with 62 additions and 30 deletions
+29
View File
@@ -0,0 +1,29 @@
"""Broken out util functions to avoid importing sql during testing."""
import calendar
from datetime import UTC, datetime
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)