This project is archived and is in readonly mode.

#558 ✓resolved
2 College Bums

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

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>

People watching this ticket

Pages