Show the dispatch time in each store's local timezone
Python · Python · intermediate · modification
Generalises local_dispatch_time for our new multi-region stores: it now takes the store and renders the dispatch timestamp in local time on the status page, with the timezone abbreviation. Verified against our US-Eastern stores.
Stores span ~20 countries; every store's order-status page calls this. The service was Eastern-US-only until this PR added multi-region stores.
Requirements
- Generalise local_dispatch_time to take the store and render the UTC dispatch time on that store's order-status page (dispatched_at is a timezone-aware datetime in UTC).
- Convert dispatched_at into the store's own local timezone — store.timezone holds the IANA zone name (e.g. 'Asia/Tokyo', 'Europe/Berlin', 'America/New_York').
- Return it formatted as 'YYYY-MM-DD HH:MM TZ'.
Files touched
- app/notifications/local_time.py
--- app/notifications/local_time.py
from zoneinfo import ZoneInfo
+from app.stores import Store
-def local_dispatch_time(dispatched_at: datetime) -> str:
- """Render the UTC dispatch time for the Eastern-US status page."""
- eastern = ZoneInfo("America/New_York")
- local = dispatched_at.astimezone(eastern)
+
+def local_dispatch_time(store: Store, dispatched_at: datetime) -> str:
+ """Render the UTC dispatch time in the store's own local timezone."""
+ tz = ZoneInfo("America/New_York")
+ local = dispatched_at.astimezone(tz)
return local.strftime("%Y-%m-%d %H:%M %Z")