52 lines
1.6 KiB
Python
52 lines
1.6 KiB
Python
"""
|
|
Daily intake-window helpers.
|
|
|
|
Intake runs on a schedule (8AM-3:30PM by default), so it's useful to
|
|
know when a ticket arrived relative to the cutoff - a ticket created
|
|
after INTAKE_CUTOFF_TIME didn't have a full window to get processed
|
|
same-day, which helps explain carryover rather than just seeing it as
|
|
unexplained backlog.
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import datetime as dt
|
|
from typing import Optional
|
|
|
|
from app import config
|
|
|
|
|
|
def parse_cutoff_time(raw: str) -> Optional[dt.time]:
|
|
raw = (raw or "").strip()
|
|
if not raw:
|
|
return None
|
|
try:
|
|
hour_str, minute_str = raw.split(":")
|
|
return dt.time(int(hour_str), int(minute_str))
|
|
except (ValueError, TypeError):
|
|
return None
|
|
|
|
|
|
def get_cutoff_time() -> Optional[dt.time]:
|
|
return parse_cutoff_time(
|
|
config.get("INTAKE_CUTOFF_TIME", config.DEFAULT_INTAKE_CUTOFF_TIME)
|
|
)
|
|
|
|
|
|
def is_past_cutoff(created_at: Optional[dt.datetime], cutoff: Optional[dt.time]) -> bool:
|
|
if not created_at or not cutoff:
|
|
return False
|
|
return created_at.time() > cutoff
|
|
|
|
|
|
def is_past_cutoff_today(created_at: Optional[dt.datetime], cutoff: Optional[dt.time]) -> bool:
|
|
"""
|
|
Same as is_past_cutoff, but only true for TODAY's late arrivals - the
|
|
flag is meant to mean "this one came in too late for today's window",
|
|
not a permanent marker. Once the next business day starts, a ticket
|
|
that arrived late yesterday is carryover (a different, already-tracked
|
|
concept), not "past cutoff" anymore.
|
|
"""
|
|
if not created_at or created_at.date() != dt.date.today():
|
|
return False
|
|
return is_past_cutoff(created_at, cutoff)
|