Welcome to mirror list, hosted at ThFree Co, Russian Federation.

time_helper.rb « helpers « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 94044d7b85ec0fbb74ef0990e5c4030d629d9304 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# frozen_string_literal: true

module TimeHelper
  def time_interval_in_words(interval_in_seconds)
    interval_in_seconds = interval_in_seconds.to_i
    minutes = interval_in_seconds / 60
    seconds = interval_in_seconds - minutes * 60

    if minutes >= 1
      if seconds % 60 == 0
        pluralize(minutes, "minute")
      else
        [pluralize(minutes, "minute"), pluralize(seconds, "second")].to_sentence
      end
    else
      pluralize(seconds, "second")
    end
  end

  def date_from_to(from, to)
    "#{from.to_s(:short)} - #{to.to_s(:short)}"
  end

  def duration_in_numbers(duration)
    time_format = duration < 1.hour ? "%M:%S" : "%H:%M:%S"

    Time.at(duration).utc.strftime(time_format)
  end
end