From 1cd0b152019897eab755c345453fcd06ac9dd6b7 Mon Sep 17 00:00:00 2001 From: Peter Stockings Date: Sun, 29 Dec 2024 11:31:12 +1100 Subject: [PATCH] Show current local time default when adding new reading --- app/routes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/app/routes.py b/app/routes.py index 03540c5..cef6adb 100644 --- a/app/routes.py +++ b/app/routes.py @@ -275,6 +275,12 @@ def add_reading(): db.session.commit() flash("Reading added successfully.", "success") return redirect(url_for('main.dashboard')) + + # Fetch the user's timezone (default to 'UTC' if none is set) + user_timezone = current_user.profile.timezone if current_user.profile and current_user.profile.timezone else 'UTC' + local_tz = timezone(user_timezone) + + form.timestamp.data = utc.localize(datetime.utcnow()).astimezone(local_tz) return render_template('add_reading.html', form=form) @main.route('/reading//edit', methods=['GET', 'POST'])