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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

40 lines
1 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
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
2022-11-25 23:54:43 +05:30
n_('%d minute', '%d minutes', minutes) % minutes
2018-11-18 11:00:15 +05:30
else
2022-11-25 23:54:43 +05:30
[n_('%d minute', '%d minutes', minutes) % minutes, n_('%d second', '%d seconds', seconds) % seconds].to_sentence
2018-11-18 11:00:15 +05:30
end
2015-10-24 18:46:33 +05:30
else
2022-11-25 23:54:43 +05:30
n_('%d second', '%d seconds', seconds) % seconds
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
2018-12-13 13:39:08 +05:30
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
2018-12-05 23:21:45 +05:30
2018-12-13 13:39:08 +05:30
if hours == 0
"%02d:%02d" % [minutes, seconds]
2018-12-05 23:21:45 +05:30
else
2018-12-13 13:39:08 +05:30
"%02d:%02d:%02d" % [hours, minutes, seconds]
2018-12-05 23:21:45 +05:30
end
2016-08-24 12:49:21 +05:30
end
2021-01-29 00:20:46 +05:30
def time_in_milliseconds
(Time.now.to_f * 1000).to_i
end
2015-10-24 18:46:33 +05:30
end