Skip to content

Instantly share code, notes, and snippets.

@nahi
Created October 31, 2011 04:29
Show Gist options
  • Save nahi/1326912 to your computer and use it in GitHub Desktop.
Save nahi/1326912 to your computer and use it in GitHub Desktop.
require 'date'
class Date
# Try to read Marshal data of 1.9.3 Date
# !!CAUTION: COMPLETELY UNTESTED!!!
if RUBY_VERSION < "1.9.3"
def marshal_load(ary)
case ary.size
when 3
@ajd, @of, @sg, = ary
when 6
nth, jd, df, sf, of, sg, = ary
@ajd = jd + nth * 71149239
df -= 86400 / 2
if df.nonzero?
@ajd += df.to_r / 86400
end
if sf.nonzero?
@ajd += sf.to_r / (86400 * 1000000000)
end
if of.nonzero?
@of = of.to_r / 86400
else
@of = 0
end
@sg = sg.to_i
else
raise TypeError, "cannot read Date"
end
@__ca__ = {}
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment