I ran into this issue while testing a rails app deployed to two different staging servers, in different time zones (PDT and CDT). Both servers have rails using the default UTC config.time_zone. Apart from the timezone configuration being different, both servers have their clocks set correctly.
Below is what I see in a rails console:
On the server where system timezone is CDT,
Time.zone.parse("Mon May 28 2012 00:00:00 GMT-0700 (PDT)")
=> Mon, 28 May 2012 05:00:00 UTC +00:00
On the server where system timezone is PDT,
Time.zone.parse("Mon May 28 2012 00:00:00 GMT-0700 (PDT)")
=> Mon, 28 May 2012 07:00:00 UTC +00:00
The string Mon May 28 2012 00:00:00 GMT-0700 (PDT) is an arbitrary date-time value sent by a client. This is a common scenario when using a javascript Date object coming in via the rails params collection.
Why are the two results Time.zone.parse(identical_date_time_string) different?
If I run the following on both systems, the result appears correct:
"Mon May 28 2012 00:00:00 GMT-0700 (PDT)".to_time
=> 2012-05-28 07:00:00 UTC
I’m running rails 3.2.3 with ruby 1.9.3-p125, on ubuntu.
ActiveSupportTimeZone.parsemakes no attempt to extract the time zone information out of the given string. It simply extracts the date and time and converts it to a TimeWithZone with the given (local) time zone.str.to_timewill take notice of the “GMT-0700” line, but will produce a time without a time zone.You could fudge it by extracting the “GMT…..” part and converting that to a UTC offset, which is close to, but not exactly, the time zone.