lib/fugit/duration.rb in fugit-1.8.0 vs lib/fugit/duration.rb in fugit-1.8.1

- old
+ new

@@ -66,13 +66,15 @@ wee: { a: 'W', r: 'w', i: 'W', s: 7 * DAY_S, I: true, l: 'week' }, day: { a: 'D', r: 'd', i: 'D', s: DAY_S, I: true, l: 'day' }, hou: { a: 'h', r: 'h', i: 'H', s: 3600, I: true, l: 'hour' }, min: { a: 'm', r: 'm', i: 'M', s: 60, I: true, l: 'minute' }, sec: { a: 's', r: 's', i: 'S', s: 1, I: true, l: 'second' } }.freeze - INFLA_KEYS, NON_INFLA_KEYS = - KEYS.partition { |k, v| v[:I] }.freeze + INFLA_KEYS, NON_INFLA_KEYS = KEYS + .partition { |k, v| v[:I] } + .collect(&:freeze) + def _to_s(key) KEYS.inject([ StringIO.new, '+' ]) { |(s, sign), (k, a)| v = @h[k] next [ s, sign ] unless v @@ -238,11 +240,11 @@ if at[1] > 12 n, m = at[1] / 12, at[1] % 12 at[0], at[1] = at[0] + n, m elsif at[1] < 1 - n, m = -at[1] / 12, -at[1] % 12 + n, m = (-at[1]) / 12 + 1, (11+at[1]) % 12 + 1 at[0], at[1] = at[0] - n, m end t = ::EtOrbi.make_time(at, t.zone) end @@ -267,10 +269,10 @@ case a when Numeric then add_numeric(-a) when Fugit::Duration then add_duration(-a) when String then add_duration(-self.class.parse(a)) - when ::Time, ::EtOrbi::EoTime then add_to_time(a) + when ::Time, ::EtOrbi::EoTime then opposite.add_to_time(a) else fail ArgumentError.new( "cannot subtract #{a.class} instance to a Fugit::Duration") end end alias - subtract