Rails 2.1 UTC & Local Time

I wrote the follwoing code to force the time before saving a record (using UTC in my config environment)

      e = self.ending_at       self.starting_at = Time.utc(s.to_date.year, s.to_date.month, s.to_date.day, 0, 0, 1)

self.starting_at => Fri, 01 Feb 2008 00:00:01 UTC +00:00

BUT now, I would like to use time zones in my app (setting config.time_zone = "Madrid") the user gives a date in the form (Fri, 01 Feb 2008) the time is forced to be 00:00:01 as above the date is saved as being Fri, 01 Feb 2008 00:00:01 in Madrid (UTC + 01:00)

any trick ?

erwin

you want to set the database to use utc in environment.rb :

config.time_zone = ‘UTC’

And then store users timezone in your DB and then set config.timezone in a before_filter in your app.

That will allow the users to deal with their local timezone , but store everything in UTC.

http://mad.ly/2008/04/09/rails-21-time-zone-support-an-overview/

Adam