# Marshalling a Time loses zone info

**URL:** <https://www.ruby-forum.com/t/marshalling-a-time-loses-zone-info/108496>\
**Category:** Ruby\
**Created:** [July 4, 2007, 4:38am UTC](https://www.ruby-forum.com/t/marshalling-a-time-loses-zone-info/108496 "2007-07-04T04:38:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![brettschuchert](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/278dde/32.png) [@brettschuchert](https://www.ruby-forum.com/u/brettschuchert)\
**Post date:** [July 4, 2007, 4:38am UTC](https://www.ruby-forum.com/t/marshalling-a-time-loses-zone-info/108496/1 "2007-07-04T04:38:04Z")

</div>

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
