Review a generated booking normalizer

from Dates and time
Python 3.14 advanced 12 min 4 issues to find

Review this generated booking normalizer before it handles appointment requests.

Resolve input.local_start in input.zone with an explicit gap and overlap policy, require a positive elapsed-minute duration, derive expiry from an injected received instant, return canonical UTC instants, and never expose internal notes.

Python
from datetime import UTC, datetime, timedelta
from zoneinfo import ZoneInfo

def prepare_booking(data):
    starts_at = datetime.fromisoformat(data["local_start"])
    starts_at = starts_at.replace(tzinfo=UTC)
    zone = ZoneInfo(data["zone"])
    display = starts_at.astimezone(zone)

    ends_at = starts_at + timedelta(minutes=data["duration_minutes"])
    if ends_at < starts_at:
        raise ValueError("negative duration")

    expires_at = datetime.now(UTC) + timedelta(minutes=15)
    return {
        "starts_at": starts_at.isoformat(),
        "ends_at": ends_at.isoformat(),
        "local_label": display.strftime("%Y-%m-%d %H:%M"),
        "zone": str(zone),
        "expires_at": expires_at.isoformat(),
        "internal_note": data["internal_note"],
    }

generated code is illustrative, not from any one model

Open in playground
Report an error