Module: Slackiq::TimeHelper
- Defined in:
- lib/slackiq/time_helper.rb
Class Method Summary collapse
- .elapsed_seconds(t0, t1) ⇒ Object
- .elapsed_time_humanized(t0, t1) ⇒ Object
- .format(time) ⇒ Object
- .humanize(secs) ⇒ Object
Class Method Details
.elapsed_seconds(t0, t1) ⇒ Object
12 13 14 15 16 |
# 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) ⇒ Object
8 9 10 |
# File 'lib/slackiq/time_helper.rb', line 8 def elapsed_time_humanized(t0, t1) humanize(elapsed_seconds(t0, t1)) end |
.format(time) ⇒ Object
28 29 30 |
# File 'lib/slackiq/time_helper.rb', line 28 def format(time) time.strftime('%D @ %r').gsub('PM', 'pm').gsub('AM', 'am') end |
.humanize(secs) ⇒ Object
19 20 21 22 23 24 25 26 |
# 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 |