Marshalling a Time loses zone info

Discussion in 'Ruby' started by Brett Simmers, Jul 4, 2007.

  1. I was dealing with a weird problem today that I eventually traced back
    to the fact that marshalling and unmarshalling a Time object will
    implicitly convert it to local time:

    t = Time.new
    t.utc
    s = Marshal.dump t
    new_t = Marshal.load s
    t.to_s # "Wed Jul 04 02:09:05 UTC 2007"
    new_t.to_s # "Tue Jul 03 19:09:05 -0700 2007"

    I know that they still represent the same time, but it seems to me like
    the zone is an important part of the state of the object. Is this
    intentional or a bug? This was a problem because my app is getting
    objects from a database that's running in UTC. It gets some Time
    objects from the db adapter and sends them, along with some other data,
    over the network using DRb (which uses Marshal.dump/load). These are
    then used in another query back to the same database, but the adapter
    (OCI8) ignores the time zone. As a result, the times it was using in
    the queries would be 7 hours behind what they should be. I solved it by
    calling .utc on any Time objects that come in over the network to make
    sure everything is UTC, but it was an interesting problem. I'm using
    1.8.6, I haven't tried it with 1.9 yet.

    -Brett
     
    Brett Simmers, Jul 4, 2007
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ryu

    Time Zone in Windows Time

    Ryu, Sep 15, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    18,410
    madamut
    Feb 11, 2009
  2. =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=

    prevent a postback when moving web parts from zone to zone.

    =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=, Feb 8, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    592
    =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=
    Feb 8, 2006
  3. davout
    Replies:
    3
    Views:
    570
    Roedy Green
    Oct 16, 2003
  4. J.H.Kim

    time adjustment code according to time zone

    J.H.Kim, Oct 24, 2011, in forum: C Programming
    Replies:
    3
    Views:
    479
    Joel C. Salomon
    Oct 24, 2011
Loading...

Share This Page