2018-08-18 07:19:57 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
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
|
2022-09-23 02:10:24 -04:00
|
|
|
n_('%d minute', '%d minutes', minutes) % minutes
|
2018-07-10 06:49:28 -04:00
|
|
|
else
|
2022-09-23 02:10:24 -04:00
|
|
|
[n_('%d minute', '%d minutes', minutes) % minutes, n_('%d second', '%d seconds', seconds) % seconds].to_sentence
|
2018-07-10 06:49:28 -04:00
|
|
|
end
|
2015-09-29 10:26:40 -04:00
|
|
|
else
|
2022-09-23 02:10:24 -04:00
|
|
|
n_('%d second', '%d seconds', seconds) % seconds
|
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
|
|
|
|
2018-10-10 01:27:16 -04:00
|
|
|
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
|
2016-08-09 06:42:42 -04:00
|
|
|
|
2018-10-10 01:27:16 -04:00
|
|
|
if hours == 0
|
|
|
|
"%02d:%02d" % [minutes, seconds]
|
2018-09-27 07:44:03 -04:00
|
|
|
else
|
2018-10-10 01:27:16 -04:00
|
|
|
"%02d:%02d:%02d" % [hours, minutes, seconds]
|
2018-09-27 07:44:03 -04:00
|
|
|
end
|
2016-07-06 15:00:20 -04:00
|
|
|
end
|
2020-10-27 08:08:33 -04:00
|
|
|
|
|
|
|
def time_in_milliseconds
|
|
|
|
(Time.now.to_f * 1000).to_i
|
|
|
|
end
|
2015-09-29 10:26:40 -04:00
|
|
|
end
|