Selaa lähdekoodia

Setup timezone in "web" part so that timestamps are properly displayed

jherve 1 vuosi sitten
vanhempi
commit
f1f96c934c
2 muutettua tiedostoa jossa 9 lisäystä ja 5 poistoa
  1. 0 4
      README.md
  2. 9 1
      src/de_quoi_parle_le_monde/web.py

+ 0 - 4
README.md

@@ -46,7 +46,3 @@ Some snapshots are chosen even though they are up to 5/6 hours too early / too l
 SELECT timestamp-timestamp_virtual AS difference, * FROM snapshots_view
 ORDER BY difference
 ```
-
-### Time zones
-
-We want snapshots according to a given localtime, but at the moment the time is taken as UTC.

+ 9 - 1
src/de_quoi_parle_le_monde/web.py

@@ -6,6 +6,7 @@ from fastapi.templating import Jinja2Templates
 from babel.dates import format_datetime
 from babel import Locale
 import humanize
+from zoneinfo import ZoneInfo
 
 from de_quoi_parle_le_monde.medias import media_collection
 from de_quoi_parle_le_monde.storage import Storage
@@ -13,9 +14,16 @@ from de_quoi_parle_le_monde.similarity_index import SimilaritySearch
 
 
 def add_date_processing(_any):
+    # At the moment this information comes out of nowhere but one might imagine that
+    # in the future it can be deducted from the request or from information the
+    # user gives.
+    user_tz = ZoneInfo("Europe/Paris")
+
     def absolute_datetime(dt):
         return format_datetime(
-            dt, format="EEEE d MMMM @ HH:mm", locale=Locale("fr", "FR")
+            dt.astimezone(user_tz),
+            format="EEEE d MMMM @ HH:mm",
+            locale=Locale("fr", "FR"),
         )
 
     def duration(reference, target):