module Slackiq::TimeHelper

Public Class Methods

elapsed_seconds(t0, t1) click to toggle source
# File lib/slackiq/time_helper.rb, line 12
def elapsed_seconds(t0, t1)
  dt0 = t0.to_datetime
  dt1 = t1.to_datetime
  ((dt1-dt0)*24*60*60).to_i
end
elapsed_time_humanized(t0, t1) click to toggle source
# File lib/slackiq/time_helper.rb, line 8
def elapsed_time_humanized(t0, t1)
  humanize(elapsed_seconds(t0, t1))
end
format(time) click to toggle source
# File lib/slackiq/time_helper.rb, line 28
def format(time)
  time.strftime('%D @ %r').gsub('PM', 'pm').gsub('AM', 'am')
end
humanize(secs) click to toggle source

stackoverflow.com/questions/4136248/how-to-generate-a-human-readable-time-range-using-ruby-on-rails

# File lib/slackiq/time_helper.rb, line 19
def humanize(secs)
  [[60, :s], [60, :m], [24, :h], [1000, :d]].map{ |count, name|
    if secs > 0
      secs, n = secs.divmod(count)
      "#{n.to_i}#{name}"
    end
  }.compact.reverse.join(' ')
end