Explorar o código

[music] Fix timezones for TSV imports

Colin Powell hai 2 semanas
pai
achega
fc72b23b11

+ 0 - 1
vrobbler/apps/profiles/models.py

@@ -1,6 +1,5 @@
 from zoneinfo import ZoneInfo
 import pendulum
-from datetime import datetime
 from django.utils import timezone
 import logging
 from django.conf import settings

+ 5 - 4
vrobbler/apps/scrobbles/importers/tsv.py

@@ -2,6 +2,7 @@ import codecs
 import csv
 import logging
 from datetime import datetime, timedelta
+from zoneinfo import ZoneInfo
 
 import requests
 from django.contrib.auth import get_user_model
@@ -61,10 +62,10 @@ def import_audioscrobbler_tsv_file(file_path, user_id):
                 },
             )
             continue
-
-        timestamp = user.profile.get_timestamp_with_tz(
-            datetime.fromtimestamp(int(row[AsTsvColumn["TIMESTAMP"].value]))
-        )
+        timestamp = datetime.fromtimestamp(
+            int(row[AsTsvColumn["TIMESTAMP"].value])
+        ).astimezone(ZoneInfo("UTC"))
+        timestamp = user.profile.get_timestamp_with_tz(timestamp)
         stop_timestamp = timestamp + timedelta(seconds=track.run_time_seconds)
 
         new_scrobble = Scrobble(