From: matt [mailto:mhm26@drexel.edu]
Sent: 13 May 2004 20.24
Subject: Bug in Marshal?With the usual deep_copy:
Deep copy
class Object
def deep_copy
Marshal.load(Marshal.dump(self))
end
endI get the following (irb 0.9(02/07/03))
irb(main):001:0> fmt = “%m-%d-%Y %H:%M”
=> “%m-%d-%Y %H:%M”original = Time.gm(2004, 04, 25, 22, 56)
=> Sun Apr 25 22:56:00 UTC 2004
copy = original.deep_copy
=> Sun Apr 25 18:56:00 Eastern Daylight Time 2004
[original, copy].map {|t| t.strftime(fmt)}
=> [“04-25-2004 22:56”, “04-25-2004 18:56”]
original.hour
=> 22
copy.hour
=> 18
original.hour <=> copy.hour
=> 1
original <=> copy
=> 0
Not as bad as all that; I think that it’s an artifact of how Time is
constructed, not in Marshal. If you know you’re dealing with Time, and
want deal only with UTC (GMT) times, do:
copy = original.deep_copy.utc
Logically, copy.zone should be the same as original.zone, but as I said,
I think that’s a Time problem.
-austin
···
–
austin ziegler * austin.ziegler@evault.com