Sha256: ec34423c5eacca5b2f177f20191da6403168c1d33dc1a274b1fbea889e1dc32f

Contents?: true

Size: 938 Bytes

Versions: 18

Compression:

Stored size: 938 Bytes

Contents

module Naf
  module TimeHelper

    def time_difference(value, started_at = nil)
      seconds = value % 60
      value = (value - seconds) / 60
      minutes = value % 60
      value = (value - minutes) / 60
      hours = value % 24
      value = (value - hours) / 24
      days = value % 7
      more_hours = hours + days * 24 if days > 0

      if started_at.present?
        "-#{hours.to_i + more_hours.to_i}h#{minutes.to_i}m, #{started_at.localtime.strftime("%Y-%m-%d %r")}"
      else
        if days < 2
          "-#{hours.to_i + more_hours.to_i}h#{minutes.to_i}m#{seconds.to_i}s"
        else
          "-#{days.to_i}d#{hours.to_i}h#{minutes.to_i}m#{seconds.to_i}s"
        end
      end
    end

    def time_format(time)
      return '' if time.nil?

      value = Time.zone.now - time
      if value < 60
        return "#{value.to_i} seconds ago"
      else
        return time_difference(value)
      end
    end

  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
naf-2.1.13 app/helpers/naf/time_helper.rb
naf-2.1.12 app/helpers/naf/time_helper.rb
naf-2.1.11 app/helpers/naf/time_helper.rb
naf-2.1.10 app/helpers/naf/time_helper.rb
naf-2.1.9 app/helpers/naf/time_helper.rb
naf-2.1.8 app/helpers/naf/time_helper.rb
naf-2.1.6 app/helpers/naf/time_helper.rb
naf-2.1.5 app/helpers/naf/time_helper.rb
naf-2.1.4 app/helpers/naf/time_helper.rb
naf-2.1.3 app/helpers/naf/time_helper.rb
naf-2.1.2 app/helpers/naf/time_helper.rb
naf-2.1.1 app/helpers/naf/time_helper.rb
naf-2.1.0 app/helpers/naf/time_helper.rb
naf-2.0.4 app/helpers/naf/time_helper.rb
naf-2.0.3 app/helpers/naf/time_helper.rb
naf-2.0.2 app/helpers/naf/time_helper.rb
naf-2.0.1 app/helpers/naf/time_helper.rb
naf-2.0.0 app/helpers/naf/time_helper.rb