mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
24 lines
634 B
Python
24 lines
634 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_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"
|