from __future__ import annotations from datetime import datetime, timedelta, timezone # India Standard Time is a fixed UTC+05:30 offset (no DST). IST = timezone(timedelta(hours=5, minutes=30)) def now_ist() -> datetime: """Return a timezone-aware datetime in IST.""" return datetime.now(IST) def ensure_ist(value: datetime) -> datetime: """Coerce a datetime to IST. If naive, assume it represents IST wall-clock time. Note: SQLite often strips tzinfo even when timezone-aware datetimes are provided. """ if value.tzinfo is None: value = value.replace(tzinfo=IST) return value.astimezone(IST) def iso_now_ist() -> str: """Return an ISO-8601 timestamp string in IST, truncated to seconds.""" return now_ist().replace(microsecond=0).isoformat()