Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

TimeWithZone fails to unmarshal properly

#558

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

Reported by 2 College Bums · July 7th, 2008 @ 10:16 AM

State: resolved
Milestone: 2.x
Assigned to: Geoff Buesing Geoff Buesing
Importance: none

Activity

  1. Geoff Buesing
    Geoff Buesing
    • 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.

    July 7th, 2008 @ 09:21 PM

  2. 2 College Bums
    2 College Bums

    We don't feel comfortable in creating a patch ourselves, but thanks for the opportunity.

    July 8th, 2008 @ 09:08 PM

  3. Geoff Buesing
    Geoff Buesing
    • State changed from open to resolved

    July 15th, 2008 @ 05:19 AM