B
Brett Simmers
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
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