debian-mirror-gitlab/app/helpers/time_helper.rb

28 lines
691 B
Ruby
Raw Normal View History

2015-10-24 18:46:33 +05:30
module TimeHelper
def time_interval_in_words(interval_in_seconds)
2016-08-24 12:49:21 +05:30
interval_in_seconds = interval_in_seconds.to_i
2015-10-24 18:46:33 +05:30
minutes = interval_in_seconds / 60
seconds = interval_in_seconds - minutes * 60
if minutes >= 1
2018-11-18 11:00:15 +05:30
if seconds % 60 == 0
pluralize(minutes, "minute")
else
[pluralize(minutes, "minute"), pluralize(seconds, "second")].to_sentence
end
2015-10-24 18:46:33 +05:30
else
2018-11-18 11:00:15 +05:30
pluralize(seconds, "second")
2015-10-24 18:46:33 +05:30
end
end
def date_from_to(from, to)
"#{from.to_s(:short)} - #{to.to_s(:short)}"
end
2016-08-24 12:49:21 +05:30
2016-09-13 17:45:13 +05:30
def duration_in_numbers(duration)
time_format = duration < 1.hour ? "%M:%S" : "%H:%M:%S"
2016-08-24 12:49:21 +05:30
2016-09-13 17:45:13 +05:30
Time.at(duration).utc.strftime(time_format)
2016-08-24 12:49:21 +05:30
end
2015-10-24 18:46:33 +05:30
end