TimeZone problems upgrading to 3.0.6

I’ve been working on the internal app for my company which is well
over 4 years old. First commit was using Rails 1.1.6.

I’m now at 2.3.11 and I have a branch of my code that is converted to
3.0.6, but I just noticed a problem. The Rails 3 branch is pushing
timestamps with time zone manipulation. I knew that Rails had a new
way to handle time zones, but up through 2.3.11, I haven’t had to
change anything.

Is there a setting to change? I saw
“ActiveRecord::Base.time_zone_aware_attributes = true” in the docs.

The problem I have now is that is I pull a record from before the
conversion, the created_at timestamp is correct at “Mon, 02 Feb 2009
10:59:10 UTC +00:00” because that was the local time here (ignoring
the UTC part). Now when I create a new record, I get “Tue, 12 Apr
2011 21:20:10 UTC +00:00” which is 5:20 Eastern.

My ultimate question is, what should I do? I’d hate to have to switch
the app to use config.time_zone = “Eastern…” and then run a script
to touch every single timestamp and convert it in the database…

On Tue, Apr 12, 2011 at 4:40 PM, Stephen H. Gerstacker <
[email protected]> wrote:

“ActiveRecord::Base.time_zone_aware_attributes = true” in the docs.
to touch every single timestamp and convert it in the database…

That looks to me like what you will have to do. Set the system to the
time
zone you want then run an SQL to fix all the incorrect entries.

B.

On 12 April 2011 22:40, Stephen H. Gerstacker [email protected]
wrote:

“ActiveRecord::Base.time_zone_aware_attributes = true” in the docs.

The problem I have now is that is I pull a record from before the
conversion, the created_at timestamp is correct at “Mon, 02 Feb 2009
10:59:10 UTC +00:00” because that was the local time here (ignoring
the UTC part). Now when I create a new record, I get “Tue, 12 Apr
2011 21:20:10 UTC +00:00” which is 5:20 Eastern.

Are you sure exactly what is in the database itself? A datetime field
does not contain a timezone indication so the stamps you are showing
above are a Rails interpretation of what is there. First I suggest
you look at the db itself using phpmyadmin or whatever is your
favourite tool to check exactly what is there.

My ultimate question is, what should I do? I’d hate to have to switch
the app to use config.time_zone = “Eastern…” and then run a script
to touch every single timestamp and convert it in the database…

If your statement above about what is actually in the db is correct
then since timestamps in the database should always be in UTC it is
the earlier data that is incorrect. In your situation I would write a
migration to update all the earlier ones (assuming that it actually
matters whether the earlier data has the correct values).

Colin

I figured it out. I left time_zone_aware_attributes to true and set
the config.time_zone to Eastern and
config.active_record.default_timezone to local.

Since these settings were made so long ago and I just missed the boat,
I was confused.

Thanks for the help.

On Apr 12, 5:40pm, “Stephen H. Gerstacker” [email protected]