class TimeMath::Units::Simple

@private

Constants

MULTIPLIERS

Public Instance Methods

to_seconds(sz = 1) click to toggle source
# File lib/time_math/units/simple.rb, line 5
def to_seconds(sz = 1)
  sz * MULTIPLIERS[index..-1].inject(:*)
end

Protected Instance Methods

_advance(tm, steps) click to toggle source
# File lib/time_math/units/simple.rb, line 15
def _advance(tm, steps)
  _shift(tm, to_seconds(steps))
end
_decrease(tm, steps) click to toggle source
# File lib/time_math/units/simple.rb, line 19
def _decrease(tm, steps)
  _shift(tm, -to_seconds(steps))
end
_measure(from, to) click to toggle source
# File lib/time_math/units/simple.rb, line 11
def _measure(from, to)
  to.to_time.-(from.to_time)./(to_seconds).to_i
end
_shift(tm, seconds) click to toggle source
# File lib/time_math/units/simple.rb, line 23
def _shift(tm, seconds)
  case tm
  when Time
    tm + seconds
  when Date
    tm + Rational(seconds, 86_400)
  else
    raise ArgumentError, "Expected Time or DateTime, got #{tm.class}"
  end
end