Method: TimeCalc::Diff#divmod

Defined in:
lib/time_calc/diff.rb

#divmod(span, unit) ⇒ (Integer, Time or Date or DateTime) #divmod(unit) ⇒ (Integer, Time or Date or DateTime)

Combination of #div and #modulo in one operation.

Overloads:

  • #divmod(span, unit) ⇒ (Integer, Time or Date or DateTime)

    Parameters:

    • span (Integer)
    • unit (Symbol)

      Any of supported units (see TimeCalc)

  • #divmod(unit) ⇒ (Integer, Time or Date or DateTime)

    Shortcut for ‘divmod(1, unit)`

    Parameters:

    • unit (Symbol)

      Any of supported units (see TimeCalc)

Returns:

  • ((Integer, Time or Date or DateTime))


68
69
70
71
# File 'lib/time_calc/diff.rb', line 68

def divmod(span, unit = nil)
  span, unit = 1, span if unit.nil?
  div(span, unit).then { |res| [res, to.+(res * span, unit).unwrap] }
end