Module: EasyML::Support::Age

Defined in:
lib/easy_ml/support/age.rb

Class Method Summary collapse

Class Method Details

.age(start_time, end_time, format: "human") ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/easy_ml/support/age.rb', line 6

def self.age(start_time, end_time, format: "human")
  return nil unless start_time && end_time

  age_duration = ActiveSupport::Duration.build((end_time - start_time).to_i)
  age_parts = age_duration.parts

  case format.to_s
  when "human"
    age_duration.inspect
  when "days"
    age_parts[:days]
  when "hours"
    age_parts[:hours]
  when "minutes"
    age_parts[:minutes]
  when "integer"
    age_duration.to_i
  end
end