mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-07-27 23:35:01 +00:00
Behaviour-preserving lift-and-shift of the condition module out of legacy backend/condition/ into domain/condition, infrastructure/condition, infrastructure/postgres/condition_tables.py, repositories/condition, applications/condition, and tests/condition. Imports rewritten to the DDD paths; ConditionPostgres and the ORM models keep the legacy backend.app.db Base/db_session bridges so the existing suite proves behaviour is unchanged (SQLModel + session-DI conversion tracked as a follow-up in ADR-0064). 16 condition tests pass at the new location. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
18 lines
No EOL
552 B
Python
18 lines
No EOL
552 B
Python
from datetime import datetime, date
|
|
from typing import Any
|
|
|
|
|
|
def normalise_date(value: Any, allow_none: bool = True) -> date | None:
|
|
if value is None and allow_none:
|
|
return None
|
|
|
|
if isinstance(value, datetime):
|
|
return value.date()
|
|
|
|
if isinstance(value, str):
|
|
try:
|
|
return datetime.strptime(value.strip(), "%d/%m/%Y").date()
|
|
except ValueError as exc:
|
|
raise ValueError(f"Invalid date string: {value!r}") from exc
|
|
|
|
raise ValueError(f"Unexpected date value: {value!r}") |