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'])