I included user time zones:
From here, adding this in application_controller
around_action :set_time_zone
private
def set_time_zone
if current_user
Time.use_zone(current_user.time_zone) { yield }
else
yield
end
end
which produces
2020-09-21 00:00:00 +1000
This is great, but it could be more user friendly to display something along the lines of
2020-09-21 00:00 Melbourne time
Note: the word 'time' in the above is a string, nothing dynamic
The word 'Melbourne' is from the options in the view created with time_zone_options_for_select(f.object.time_zone, nil, ActiveSupport::TimeZone)
(from here)
Question
How do I adjust the set_time_zone
method so that it displays 2020-09-21 00:00 Melbourne
or 2020-09-21 00:00 Melbourne time
rather than 2020-09-21 00:00:00 +1000
?
I have tried (based on this):
def set_time_zone
if current_user
Time.use_zone(current_user.time_zone).strftime('%Z') { yield }
else
yield
end
end
but it returns the error: no block given (yield)