[birds] Properly import from tz
This commit is contained in:
@ -3,7 +3,6 @@ import logging
|
|||||||
import re
|
import re
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from zoneinfo import ZoneInfo
|
|
||||||
|
|
||||||
from django.contrib.auth import get_user_model
|
from django.contrib.auth import get_user_model
|
||||||
|
|
||||||
@ -36,11 +35,11 @@ def parse_coords(location_str):
|
|||||||
def parse_timestamp(date_str, time_str):
|
def parse_timestamp(date_str, time_str):
|
||||||
try:
|
try:
|
||||||
dt = datetime.strptime(f"{date_str} {time_str}", "%B %d, %Y %I:%M %p")
|
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):
|
except (ValueError, TypeError):
|
||||||
try:
|
try:
|
||||||
dt = datetime.strptime(date_str, "%B %d, %Y")
|
dt = datetime.strptime(date_str, "%B %d, %Y")
|
||||||
return dt.replace(tzinfo=ZoneInfo("UTC"))
|
return dt
|
||||||
except (ValueError, TypeError):
|
except (ValueError, TypeError):
|
||||||
logger.warning(f"Could not parse date/time: {date_str} {time_str}")
|
logger.warning(f"Could not parse date/time: {date_str} {time_str}")
|
||||||
return None
|
return None
|
||||||
@ -87,6 +86,8 @@ def import_birding_csv(file_path, user_id):
|
|||||||
if not timestamp:
|
if not timestamp:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
timestamp = user.profile.get_timestamp_with_tz(timestamp)
|
||||||
|
|
||||||
location_title = (
|
location_title = (
|
||||||
LOCATION_COORDS_RE.sub("", location_str).strip().rstrip(",").strip()
|
LOCATION_COORDS_RE.sub("", location_str).strip().rstrip(",").strip()
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user