2015-09-29 10:26:40 -04:00
|
|
|
module TimeHelper
|
|
|
|
def time_interval_in_words(interval_in_seconds)
|
2016-07-21 06:18:34 -04:00
|
|
|
interval_in_seconds = interval_in_seconds.to_i
|
2015-09-29 10:26:40 -04:00
|
|
|
minutes = interval_in_seconds / 60
|
|
|
|
seconds = interval_in_seconds - minutes * 60
|
|
|
|
|
|
|
|
if minutes >= 1
|
2018-07-10 06:49:28 -04:00
|
|
|
if seconds % 60 == 0
|
|
|
|
pluralize(minutes, "minute")
|
|
|
|
else
|
|
|
|
[pluralize(minutes, "minute"), pluralize(seconds, "second")].to_sentence
|
|
|
|
end
|
2015-09-29 10:26:40 -04:00
|
|
|
else
|
2018-07-10 06:49:28 -04:00
|
|
|
pluralize(seconds, "second")
|
2015-09-29 10:26:40 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def date_from_to(from, to)
|
|
|
|
"#{from.to_s(:short)} - #{to.to_s(:short)}"
|
|
|
|
end
|
2016-07-06 15:00:20 -04:00
|
|
|
|
2016-08-10 10:45:30 -04:00
|
|
|
def duration_in_numbers(duration)
|
|
|
|
time_format = duration < 1.hour ? "%M:%S" : "%H:%M:%S"
|
2016-08-09 06:42:42 -04:00
|
|
|
|
2016-08-10 10:45:30 -04:00
|
|
|
Time.at(duration).utc.strftime(time_format)
|
2016-07-06 15:00:20 -04:00
|
|
|
end
|
2015-09-29 10:26:40 -04:00
|
|
|
end
|