Question

I have a problem where when saving a datetime attribute, the form returns -04:00 instead of -05:00

Using Rails 3.2.3

In application.rb:

config.time_zone = 'Eastern Time (US & Canada)'

Using MySQL with mysql2 adapter

Running @wine.released_at.localtime returns 2008-05-15 00:00:00.000000000 -04:00
Running @wine.released_at returns 2008-05-15 04:00:00.000000000 Z
Running Time.now.zone returns Eastern Standard Time
Running @wine.released_at.zone returns EDT

I'm fairly confused. I though setting config.time_zone should make it such that Rails automatically converts all database datetime values to the set time_zone...why isn't this happening?

Was it helpful?

Solution

It looks to me as if the zone property returns the name of the "zone interval" which is applicable for the specified time. So for a summer time it will return "EDT" but for a winter time it will return "Easter Standard Time". (It's odd that it uses an abbreviation for one but not the other, but hey...)

So it is using the same time zone for both - those are just different aspects within the same time zone: sometimes it's standard time, sometimes it's daylight saving time.

If you print Time.now.localtime it should show you a -05:00 to show that the current offset from UTC in Eastern Time is -5 hours (i.e. Eastern Time is currently 5 hours behind UTC).

OTHER TIPS

Have you tried using in_time_zone?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top