Model/etl/hubspot/utils.py
Daniel Roth 88093eb7cd Abri deal abandonment requires at least three parseable attempts 🟩
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-03 10:10:03 +00:00

33 lines
809 B
Python

from datetime import datetime, timezone
from typing import Optional
def parse_hs_date(value: Optional[str]) -> Optional[datetime]:
if not value:
return None
try:
dt = datetime.fromisoformat(value.replace("Z", "+00:00"))
if dt.tzinfo is None:
return dt.replace(tzinfo=timezone.utc)
return dt.astimezone(timezone.utc)
except ValueError:
return None
def parse_hs_int(value: Optional[str]) -> Optional[int]:
if not value:
return None
try:
return int(value)
except ValueError:
return None
def parse_hs_bool(value: Optional[str]) -> Optional[bool]:
if value is None or value == "":
return None
if isinstance(value, bool):
return value
return str(value).strip().lower() == "true"