BigW Consortium Gitlab

time_helper.rb 602 Bytes
Newer Older
1 2
module TimeHelper
  def time_interval_in_words(interval_in_seconds)
3
    interval_in_seconds = interval_in_seconds.to_i
4 5 6 7 8 9 10 11 12 13 14 15 16
    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

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

18 19
  def duration_in_numbers(duration)
    time_format = duration < 1.hour ? "%M:%S" : "%H:%M:%S"
20

21
    Time.at(duration).utc.strftime(time_format)
22
  end
23
end