Move get_quarter_cycle into election_utils.py.
This commit is contained in:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user