[birds] Properly import from tz
All checks were successful
build & deploy / test (push) Successful in 1m52s
build & deploy / build-and-deploy (push) Successful in 33s

This commit is contained in:
2026-05-17 10:07:13 -04:00
parent cd4f6ff71d
commit 11bde2a306

View File

@ -3,7 +3,6 @@ import logging
import re
from collections import defaultdict
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo
from django.contrib.auth import get_user_model
@ -36,11 +35,11 @@ def parse_coords(location_str):
def parse_timestamp(date_str, time_str):
try:
dt = datetime.strptime(f"{date_str} {time_str}", "%B %d, %Y %I:%M %p")
return dt.replace(tzinfo=ZoneInfo("UTC"))
return dt
except (ValueError, TypeError):
try:
dt = datetime.strptime(date_str, "%B %d, %Y")
return dt.replace(tzinfo=ZoneInfo("UTC"))
return dt
except (ValueError, TypeError):
logger.warning(f"Could not parse date/time: {date_str} {time_str}")
return None
@ -87,6 +86,8 @@ def import_birding_csv(file_path, user_id):
if not timestamp:
continue
timestamp = user.profile.get_timestamp_with_tz(timestamp)
location_title = (
LOCATION_COORDS_RE.sub("", location_str).strip().rstrip(",").strip()
)