I'm looking at converting our Rails 2.3 application to correctly handle time zones (at the moment everything is in UTC which isn't right, but is convenient!).
I have these settings in environment.rb:
config.active_record.default_timezone = :utc
config.time_zone = "UTC"
Going forward, on each request in our app I plan on making the following setting to set the Time Zone:
Time.zone = user.time_zone
Where user.time_zone
is their chosen preference (e.g. US Pacific Time
).
This works fine in the app, but my question relates to what Rails then stores in the MySQL DB. If the user chooses a date of 1st June 2009, this gets stored in a DATETIME
field in the database in UTC but with the time zone offset. For example, if the user has selected a GMT+6
time zone, a chosen date of 1st June 2009 ends up in the database as 2009-06-01 06:00:00 UTC
.
I would have expected this to be stored as 2009-06-01 00:00:00 UTC
in the database. Is my thinking correct or is Rails doing something unexpected here?