Show current local time default when adding new reading

This commit is contained in:
Peter Stockings
2024-12-29 11:31:12 +11:00
parent 07ae62c633
commit 1cd0b15201

View File

@@ -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/<int:reading_id>/edit', methods=['GET', 'POST'])