module TimeSupport

Public Class Methods

seconds_to_units(seconds, include_zeros: false, round_seconds: true) click to toggle source
# File lib/bumbleworks/api/lib/time_support.rb, line 3
def seconds_to_units(seconds, include_zeros: false, round_seconds: true)
  seconds = seconds.to_i if round_seconds
  units = Hash[
    [:days, :hours, :minutes, :seconds].zip(
      [60, 60, 24].inject([seconds]) {|result, unitsize|
        result.unshift(*result.shift.divmod(unitsize))
        result
      }
    )
  ]
  units.reject! { |k,v| v == 0 } unless include_zeros
  units
end
seconds_to_units_in_words(seconds, **options) click to toggle source
# File lib/bumbleworks/api/lib/time_support.rb, line 17
def seconds_to_units_in_words(seconds, **options)
  seconds_to_units(seconds, options).map { |unit, num|
    "#{num} #{unit}"
  }.join(', ')
end