Topic: Timezones in Rails

I have an application where I want to allow the user to set timezones. When the user creates a reminder entry, the entry will be stored in db in UTC. But when he opens the calendar entry in the app, he should see the entry in his selected timezone. I am using Chronic but that is immaterial here. In my ApplicationController.rb, I have the following string :

before_filter :set_user_time_zone
...
def set_user_time_zone
    Time.zone = current_user.timezone if user_signed_in?
end

After this, the entries are still saved in UTC but with the time difference. For example, I set the timezone as - "Delhi" which is +530 from UTC. When I want to save calendar entry for "Jan, 16 - 12:15 AM" - the database is populated with "2011-01-15 18:45:19 UTC" - so its 5:30 hours before the actual time I want to save. In the UI also I keep seeing this entry instead of the the time displayed in the current user's timezone. I want to know what should be correct way to handle this kind of timezone features in rails.

Re: Timezones in Rails

yeah you're probably right in this matter. I found myself getting angry several times in a row since I keep changing and altering the time every moment I open my files..



mattress stores Philadelphia

serta Philadelphia

Re: Timezones in Rails

Oh.. Why should be angry? Maybe the system is under repair.

mattress store philadelphia

Last edited by AngelicaSimpson (2011-08-28 03:33:27)