This project is archived and is in readonly mode.
TimeWithZone fails to unmarshal properly
Reported by 2 College Bums | July 7th, 2008 @ 10:16 AM | in 2.x
When marshaling a TimeWithZone, it will marshal properly. However, when unmarshaling that same object the time will change destructively.
This is a sample on a rails 2.1 development irb
Time.zone = "Hawaii"
a = Time.zone.now
=> Sun, 06 Jul 2008 23:10:41 HST -10:00
b = Marshal.dump(a)
c = Marshal.load(b)
=> Mon, 07 Jul 2008 02:10:41 HST -10:00
a.in_time_zone
=> Sun, 06 Jul 2008 23:10:41 HST -10:00
c.in_time_zone
=> Mon, 07 Jul 2008 02:10:41 HST -10:00
a.utc
=> Mon Jul 07 09:10:41 UTC 2008
c.utc
=> Mon Jul 07 12:10:41 +0300 2008
The loaded times are considered equal and are equal when converted to utc. However the unmarshalled time is still not presented in UTC when requested.
This can be resolved with:
module ActiveSupport
class TimeWithZone
def marshal_load(variables)
initialize(variables[0].utc, ::Time.send!(:get_zone, variables[1]))
end
Comments and changes to this ticket
-
Geoff Buesing July 7th, 2008 @ 09:21 PM
- State changed from new to open
- Assigned user set to Geoff Buesing
Good catch. The call to #utc should fix this. In addition to asserting equality in the tests, we should also assert mtime.utc.utc? and mtime.time.utc? to check for this.
Feel free to roll this into a proper patch if you want; otherwise, easy enough for me to add this fix in.
-
2 College Bums July 8th, 2008 @ 09:08 PM
We don't feel comfortable in creating a patch ourselves, but thanks for the opportunity.
-
Geoff Buesing July 15th, 2008 @ 05:19 AM
- State changed from open to resolved
Resolved in http://github.com/rails/rails/co...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>