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. Advertisements

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. Oliver

    Time Zone Question

    Oliver, Dec 30, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    582
    Dino Chiesa [Microsoft]
    Jan 3, 2005
  2. Rob T

    Time Zone question

    Rob T, Jul 15, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    614
    Aaron [SQL Server MVP]
    Jul 15, 2004
  3. Ryu

    Time Zone in Windows Time

    Ryu, Sep 15, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    18,794
    madamut
    Feb 11, 2009
  4. =?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:
    758
    =?Utf-8?B?VmluY2UgVmFyYWxsbw==?=
    Feb 8, 2006
  5. davout
    Replies:
    3
    Views:
    708
    Roedy Green
    Oct 16, 2003
  6. flamesrock
    Replies:
    8
    Views:
    787
    Hendrik van Rooyen
    Nov 24, 2006
  7. J.H.Kim

    time adjustment code according to time zone

    J.H.Kim, Oct 24, 2011, in forum: C Programming
    Replies:
    3
    Views:
    554
    Joel C. Salomon
    Oct 24, 2011
  8. Replies:
    9
    Views:
    470
    Michal Kleczek
    May 27, 2013
Loading...