From ff66583b7b80d866b98327d3e3735fd884b970cd Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sat, 28 Dec 2024 23:41:06 +1100 Subject: [PATCH] Ensure the local timestamp is naive before localizing --- app/routes.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/routes.py b/app/routes.py index 63aeb21..b3b7c6d 100644 --- a/app/routes.py +++ b/app/routes.py @@ -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