Forum: Ruby on Rails Storing UTC time, displaying and editing in user time zone

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Helmut J. (Guest)
on 2009-03-07 11:57
(Received via mailing list)

I know that there are already some discussions/posts about this issue,
however, none of them helped me to solve my problem.

Disclaimer first: The application has done it already correctly, but
now the time conversation is broken and I don't know why.

I am storing a start and end time in my application.
Here is the behavior I want: Both values should be stored in UTC in
the db (MySQL). Displaying the values to the user in the local time
zone. The user should also edit the value in the local time zone, but
they remain stored in UTC.
Here is the behavior I have: The time values are just stored and no
conversation at all. If I have 10:45 in a form, then 10:45 is stored
in the db, although I am in = "Vienna". Basically all my
forms/views now show the wrong time. Before time was stored as 9:45
and shown as 10:45 (with in_time_zone) and also edited as 10:45.

here is my code/configs:

config.active_record.default_timezone = :utc
#  config.time_zone = 'UTC' # I tried already different combinations

<%= time_record.start_time.in_time_zone.to_formatted_s(:time) %>

<%= f.form_row 'time_records.start_time', f.datetime_select
(:start_time) %>

def set_time_zone # before filter
    zone = current_user.time_zone if logged_in?
    zone ||= 'UTC' = zone

I would really appreciate if someone could explain the behavior of
Time zones in Rails. I read posts and blogs (e.g, but
I am still not sure how or better what Rails does? Sometimes I don't
know if Rails does convert the time or not, is it a bug or not ...
Like I said I appreciate every help I can get, since this problem cost
me a lot of time and is a show stopper. Thank you!
Rick (Guest)
on 2009-03-08 03:13
(Received via mailing list)
Helmut J. (Guest)
on 2009-03-08 17:04
(Received via mailing list)
Thank you for the link, however, the post only describes an issue with
TimeZone and ActiveRecord.find. Or are TimeWithZone and Time a general
Helmut J. (Guest)
on 2009-03-08 17:30
(Received via mailing list)
I played for a couple of time now with Time TimeWithZone and the
config and now it seems that I got the behavior I want.
Still not sure if the Rails Time (zone) implementation is the best.
Ram (Guest)
on 2009-03-09 07:30
(Received via mailing list)
Hi Helmut,

Could you explain how you implemented your requirements? Its something
that will be helpful to lots of developers.
This topic is locked and can not be replied to.