Skip to content

Commit

Permalink
handle all knowns formats in Date#marshal_load
Browse files Browse the repository at this point in the history
* fixes #878
  • Loading branch information
eregon committed Sep 19, 2013
1 parent 2930659 commit ae6bb5e
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion lib/ruby/1.9/date.rb
Expand Up @@ -1552,10 +1552,37 @@ def marshal_dump() [ajd, @of, @sg] end

# Load from Marshal format.
def marshal_load(a)
ajd, of, sg, = a
ajd, of, sg = nil

case a.size
when 2 # 1.6.x
ajd = a[0] - HALF_DAYS_IN_DAY
of = 0
sg = a[1]
sg = sg ? GREGORIAN : JULIAN unless Numeric === sg
when 3 # 1.8.x, 1.9.2
ajd, of, sg = a
when 6
_, jd, df, sf, of, sg = a
of = Rational(of, 86_400)
ajd = jd - HALF_DAYS_IN_DAY
ajd += Rational(df, 86_400) if df != 0
ajd += Rational(sf, 86_400_000_000_000) if sf != 0
else
raise TypeError, "invalid size"
end

initialize(ajd, of, sg)
end

def self._load(str)
ary = Marshal.load(str)
raise TypeError, "expected an array" unless Array === ary
obj = allocate
obj.marshal_load(ary)
obj
end

end

# Class representing a date and time.
Expand Down

0 comments on commit ae6bb5e

Please sign in to comment.