feat: add operational eligibility and scheduled follow-up
This commit is contained in:
31
app/timezone_utils.py
Normal file
31
app/timezone_utils.py
Normal file
@@ -0,0 +1,31 @@
|
||||
"""Application civil-time helpers for Portuguese operators."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timezone
|
||||
from typing import Any
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
|
||||
OPERATOR_TIMEZONE = ZoneInfo("Europe/Lisbon")
|
||||
|
||||
|
||||
def parse_operator_local_datetime(value: Any) -> datetime:
|
||||
"""Interpret a form datetime as Europe/Lisbon and return the UTC instant."""
|
||||
parsed = value if isinstance(value, datetime) else datetime.fromisoformat(str(value).strip())
|
||||
if parsed.tzinfo is None:
|
||||
parsed = parsed.replace(tzinfo=OPERATOR_TIMEZONE)
|
||||
return parsed.astimezone(timezone.utc)
|
||||
|
||||
|
||||
def to_operator_datetime(value: Any) -> datetime | None:
|
||||
if not value:
|
||||
return None
|
||||
parsed = value if isinstance(value, datetime) else datetime.fromisoformat(str(value).replace("Z", "+00:00"))
|
||||
if parsed.tzinfo is None:
|
||||
parsed = parsed.replace(tzinfo=timezone.utc)
|
||||
return parsed.astimezone(OPERATOR_TIMEZONE)
|
||||
|
||||
|
||||
def format_operator_datetime(value: Any, pattern: str = "%d/%m/%Y %H:%M") -> str:
|
||||
parsed = to_operator_datetime(value)
|
||||
return parsed.strftime(pattern) if parsed else ""
|
||||
Reference in New Issue
Block a user