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

Files touched

--- 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")

Review this PR

Python practice