Andy McKay

Nov 22, 2006

Timezones in Rails


Are a bit of a mess. If you want an easy life assume that your app is only going to be ever run in one timezone and go to environment.rb and set: ENV['TZ'] = 'GMT'  <div>
</div><div>The problem I had is that it seems rails is doing a cast of the date. I set a date as GMT, put into the database, a timestamp with time zone field. Then when you get it out it casts into my local timezone: </div>

>> sa = Thingy.new
>> sa.datepoint = Time.gm(2006,12,13) => Wed Dec 13 00:00:00 UTC 2006
>> sa.save ..
>> zz = Thingy.find(:all)[1]
>> zz.datepoint => Wed Dec 13 00:00:00 PST 2006
If you are having similar problems try trawling through the following posts on this issue.
http://dev.rubyonrails.org/ticket/2282
http://dev.rubyonrails.org/ticket/4492
http://dev.rubyonrails.org/ticket/4551
http://blog.segment7.net/articles/2006/07/03/timezones-1-rails-0 

On a light note, got Plone 3.0 up and running and made a first completely useless check-in on it. Yay.