Move get_quarter_cycle into election_utils.py.

This commit is contained in:
2025-04-24 09:34:53 -04:00
parent def9c4aa79
commit 0f3596692f
2 changed files with 23 additions and 21 deletions
+22
View File
@@ -3,6 +3,8 @@
import calendar
from datetime import UTC, datetime
from .dakiny_settings import settings
def get_datetime(month_day: str) -> datetime:
"""
@@ -27,3 +29,23 @@ def get_datetime(month_day: str) -> datetime:
year -= 1
return datetime(year, month, day, tzinfo=UTC)
def get_quarter_cycle() -> int | None:
"""
Returns the index for the current cycle/quarter. Defined as between term start and end.
Can return None if entire year isn't covered by cycles.
Returns:
int: cycle index for current cycle.
"""
today = datetime.now(tz=UTC)
for cycle, election in enumerate(settings.election_cycles):
if (
today.date() >= get_datetime(election.term_start).date()
and today.date() <= get_datetime(election.term_end).date()
):
return cycle
return None