class Fugit::Duration
def deflate(options={})
def deflate(options={}) id = inflate h = id.h.dup s = h.delete(:sec) || 0 keys = INFLA_KEYS mon = options[:month] yea = options[:year] keys = keys.dup if mon || yea if mon mon = 30 if mon == true mon = "#{mon}d" if mon.is_a?(Integer) keys.unshift([ :mon, { s: Fugit::Duration.parse(mon).to_sec } ]) end if yea yea = 365 if yea == true yea = "#{yea}d" if yea.is_a?(Integer) keys.unshift([ :yea, { s: Fugit::Duration.parse(yea).to_sec } ]) end keys[0..-2].each do |k, v| vs = v[:s]; next if s < vs h[k] = (h[k] || 0) + s.to_i / vs s = s % vs end h[:sec] = s.is_a?(Integer) ? s : s.round(SECOND_ROUND) self.class.allocate.init(@original, {}, h) end