Module: TimeHelper

Defined in:
app/helpers/time_helper.rb

Instance Method Summary collapse

Instance Method Details

#date_from_to(from, to) ⇒ Object


20
21
22
# File 'app/helpers/time_helper.rb', line 20

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

#duration_in_numbers(duration_in_seconds) ⇒ Object


24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/time_helper.rb', line 24

def duration_in_numbers(duration_in_seconds)
  seconds = duration_in_seconds % 1.minute
  minutes = (duration_in_seconds / 1.minute) % (1.hour / 1.minute)
  hours = duration_in_seconds / 1.hour

  if hours == 0
    "%02d:%02d" % [minutes, seconds]
  else
    "%02d:%02d:%02d" % [hours, minutes, seconds]
  end
end

#time_interval_in_words(interval_in_seconds) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/time_helper.rb', line 4

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

  if minutes >= 1
    if seconds % 60 == 0
      pluralize(minutes, "minute")
    else
      [pluralize(minutes, "minute"), pluralize(seconds, "second")].to_sentence
    end
  else
    pluralize(seconds, "second")
  end
end