Sha256: 0dcd132cbb742e9232230e4291fd967c3bfcf98c8c77038bb330ff44aff89a2e

Contents?: true

Size: 629 Bytes

Versions: 54

Compression:

Stored size: 629 Bytes

Contents

require "active_support/duration"

module EasyML
  module Support
    module Age
      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
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
easy_ml-0.2.0.pre.rc10 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc9 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc8 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc7 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc6 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc5 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc4 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc3 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc2 lib/easy_ml/support/age.rb
easy_ml-0.2.0.pre.rc1 lib/easy_ml/support/age.rb
easy_ml-0.1.4 lib/easy_ml/support/age.rb
easy_ml-0.1.3 lib/easy_ml/support/age.rb
easy_ml-0.1.2 lib/easy_ml/support/age.rb
easy_ml-0.1.1 lib/easy_ml/support/age.rb