""" Timezone Utilities Centralized timezone handling for the Discord bot. The SBA league operates in America/Chicago time, but the production container may have ambiguous timezone config. These helpers ensure scheduling logic uses explicit timezones rather than relying on the OS default. - Internal storage/logging: UTC - Scheduling checks (freeze/thaw): America/Chicago """ from datetime import datetime, timezone from zoneinfo import ZoneInfo # League timezone — all scheduling decisions use this CHICAGO_TZ = ZoneInfo("America/Chicago") def now_utc() -> datetime: """Return the current time as a timezone-aware UTC datetime.""" return datetime.now(timezone.utc) def now_chicago() -> datetime: """Return the current time as a timezone-aware America/Chicago datetime.""" return datetime.now(CHICAGO_TZ) def to_chicago(dt: datetime) -> datetime: """Convert a datetime to America/Chicago. If *dt* is naive (no tzinfo), it is assumed to be UTC. """ if dt.tzinfo is None: dt = dt.replace(tzinfo=timezone.utc) return dt.astimezone(CHICAGO_TZ) def to_discord_timestamp(dt: datetime, style: str = "f") -> str: """Format a datetime as a Discord dynamic timestamp. Args: dt: A datetime (naive datetimes are assumed UTC). style: Discord timestamp style letter. R = relative, f = long date/short time, F = long date/time, t = short time, T = long time, d = short date, D = long date. Returns: A string like ````. """ if dt.tzinfo is None: dt = dt.replace(tzinfo=timezone.utc) return f""