Module: TimeHelper

Defined in:
app/helpers/time_helper.rb

Instance Method Summary collapse

Instance Method Details

#date_from_to(from, to) ⇒ Object


24
25
26
# File 'app/helpers/time_helper.rb', line 24

def date_from_to(from, to)
  "#{from.to_s(:short)} - #{to.to_s(:short)}"
end

#duration_in_words(finished_at, started_at) ⇒ Object


2
3
4
5
6
7
8
9
10
# File 'app/helpers/time_helper.rb', line 2

def duration_in_words(finished_at, started_at)
  if finished_at && started_at
    interval_in_seconds = finished_at.to_i - started_at.to_i
  elsif started_at
    interval_in_seconds = Time.now.to_i - started_at.to_i
  end

  time_interval_in_words(interval_in_seconds)
end

#time_interval_in_words(interval_in_seconds) ⇒ Object


12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/time_helper.rb', line 12

def time_interval_in_words(interval_in_seconds)
  minutes = interval_in_seconds / 60
  seconds = interval_in_seconds - minutes * 60

  if minutes >= 1
    "#{pluralize(minutes, "minute")} #{pluralize(seconds, "second")}"
  else
    "#{pluralize(seconds, "second")}"
  end
end