Ensure the local timestamp is naive before localizing

This commit is contained in:
Peter Stockings
2024-12-28 23:41:06 +11:00
parent 233eba4fda
commit ff66583b7b

View File

@@ -266,7 +266,11 @@ def edit_reading(reading_id):
if form.validate_on_submit():
# Convert the local timestamp back to UTC for saving
local_timestamp = form.timestamp.data
reading.timestamp = user_timezone.localize(local_timestamp).astimezone(utc)
# Ensure the local timestamp is naive before localizing
if local_timestamp.tzinfo is not None:
local_timestamp = local_timestamp.replace(tzinfo=None)
reading.timestamp = local_tz.localize(local_timestamp).astimezone(utc)
reading.systolic = form.systolic.data
reading.diastolic = form.diastolic.data