mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-19 17:03:02 +00:00
20 lines
696 B
Python
20 lines
696 B
Python
from datetime import datetime, time
|
|
from typing import Optional
|
|
|
|
from domain.abri.models import SlotCode
|
|
|
|
_MIDDAY = time(12, 0)
|
|
|
|
# HubSpot's confirmed-time field carries these half-day labels, not clock times.
|
|
_LABEL_SLOTS: dict[str, SlotCode] = {"morning": "AM", "afternoon": "PM"}
|
|
|
|
|
|
def slot_for_confirmed_time(confirmed_time: Optional[str]) -> SlotCode:
|
|
if confirmed_time is None or confirmed_time.strip() == "":
|
|
return "AD"
|
|
normalised = confirmed_time.strip()
|
|
label_slot = _LABEL_SLOTS.get(normalised.lower())
|
|
if label_slot is not None:
|
|
return label_slot
|
|
parsed = datetime.strptime(normalised, "%H:%M").time()
|
|
return "AM" if parsed < _MIDDAY else "PM"
|