views:

621

answers:

1

I am struggling with time zone support in Rails 3 beta and I would like to know if it is a bug or if I am doing something wrong. He is the problem:

> Time.zone = 'Madrid'  # it is GMT+2
 => "Madrid" 
> c = Comment.new
 => #<Comment id: nil, title: "", pub_at: nil>
> c.pub_at = Time.zone.parse('10:00:00')
 => Mon, 31 May 2010 10:00:00 CEST +02:00 
> c.save
> c
 => #<Comment id: 3, title: "", pub_at: "2010-05-31 08:00:00">
> c.reload
 => #<Comment id: 3, title: "", pub_at: "2010-05-31 08:00:00">
ruby-1.8.7-p249 > c.pub_at
 => Mon, 31 May 2010 13:00:00 CEST +02:00 

As you can see, the pub_at attribute is stored correctly in the database but when it is retrieved it adds 3 hours and I suspect that it is because it is using my local machine timezone that is in GMT-3.

The same sequence of commands in rails 2.3.5 works perfectly.

Any toughts? Should I report a ticket?

+1  A: 

Hi,

If i remember well, all the date are store into the database as UTC.

And rails and console doesn't handle the dates as the same way !

So you should try to test it within your application by setting the timezone into your application.rb

config.local_zone = 'Madrid'

And then print the value ! You sould see the correct time.

Hope this help

Arkan