Guyren,

I've dealt a lot with Time zone issues in Rails. Can you give us the code
you're using to create the record? And also the evaluation of "Time.zone"
right before creating the record?

There are lots of "gotchas" with Rails time zone handling. Indeed it should
convert times to UTC when storing to the database, and convert them back
when retrieving.

For example I've run into issues where I set Time.zone = # Eastern in
ApplicationController but in an out-of-proces rake task without that being
produces unexpected results.

Basically the gist of Rails time zone handling is that you always want to
set Time.zone to whatever the current representation of time zone is before
you do any ActiveRecord saving, and also make sure it's set before any
ActiveRecord retrieval/display of those attributes.

Also need to be careful doing Time.now - the correct approach is
Time.zone.now. Also Time.zone.parse, not DateTime.parse or whatever you
might be doing.

Ben


 On Wed, Jun 20, 2012 at 1:04 PM, Guyren Howe <[email protected]> wrote:

> I’m sure it’s just me, but this looks just wrong.
>
> My timestamp field is time without zone.
>
> I’ve got a suitable default time zone set in Rails.
>
> I create a record.
>
> I display the timestamp.
>
> The time displayed is off by 7 hours.
>
> The behavior that would make sense to me is that the value written to the
> database would always be UTC, which would get converted to the local time
> zone on display.
>
> But Rails appears to be doing the latter while not doing the former. So
> the time in the database is local time. But when I display it, it’s having
> 7 hours subtracted.
>
> This seems too obviously stupid. I must be missing something.
>
> --
> SD Ruby mailing list
> [email protected]
> http://groups.google.com/group/sdruby
>

-- 
SD Ruby mailing list
[email protected]
http://groups.google.com/group/sdruby

Reply via email to