Rails 3 Timezone error
Posted
by Juan
on Stack Overflow
See other posts from Stack Overflow
or by Juan
Published on 2010-05-31T14:02:07Z
Indexed on
2010/06/03
9:44 UTC
Read the original article
Hit count: 255
timezone
|ruby-on-rails3
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?
© Stack Overflow or respective owner