gitlab-org--gitlab-foss/app/helpers/time_helper.rb

34 lines
927 B
Ruby
Raw Normal View History

module TimeHelper
def duration_in_words(finished_at, started_at)
if finished_at && started_at
interval_in_seconds = finished_at.to_i - started_at.to_i
elsif started_at
interval_in_seconds = Time.now.to_i - started_at.to_i
end
time_interval_in_words(interval_in_seconds)
end
def time_interval_in_words(interval_in_seconds)
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
2016-07-06 15:00:20 -04:00
def duration_in_numbers(finished_at, started_at)
diff_in_seconds = finished_at.to_i - started_at.to_i
2016-07-07 17:48:10 -04:00
time_format = diff_in_seconds < 1.hour ? "%M:%S" : "%H:%M:%S"
2016-07-06 15:00:20 -04:00
Time.at(diff_in_seconds).utc.strftime(time_format)
end
end