Skip to content

Commit eaf26b5

Browse files
jirhikerCopilot
andauthored
Update services/thing_helper.py
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent f171a60 commit eaf26b5

1 file changed

Lines changed: 14 additions & 1 deletion

File tree

services/thing_helper.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,20 @@ def add_thing(
202202
notes = data.pop("notes", None)
203203
alternate_ids = data.pop("alternate_ids", None)
204204
location_id = data.pop("location_id", None)
205-
effective_start = data.get("first_visit_date")
205+
first_visit_date = data.get("first_visit_date")
206+
if first_visit_date is None:
207+
effective_start = None
208+
elif isinstance(first_visit_date, datetime):
209+
# Ensure datetime is timezone-aware; default to UTC if naive
210+
effective_start = (
211+
first_visit_date
212+
if first_visit_date.tzinfo is not None
213+
else first_visit_date.replace(tzinfo=ZoneInfo("UTC"))
214+
)
215+
else:
216+
# Interpret date-only values as midnight UTC on that date
217+
dt = datetime.combine(first_visit_date, datetime.min.time())
218+
effective_start = dt.replace(tzinfo=ZoneInfo("UTC"))
206219
group_id = data.pop("group_id", None)
207220
monitoring_frequencies = data.pop("monitoring_frequencies", None)
208221
datalogger_suitability_status = data.pop("is_suitable_for_datalogger", None)

0 commit comments

Comments
 (0)