Sha256: 1920d7d90bba969ad7be702af15d53767eda2c34902754d8aaa69f25d3e7ffea

Contents?: true

Size: 551 Bytes

Versions: 4

Compression:

Stored size: 551 Bytes

Contents

# frozen_string_literal: true

module Motoko
  module Utils
    module TimeAgo
      def seconds_to_human(value)
        return nil unless value

        value = value.round
        res = []

        {
          's' => 60,
          'm' => 60,
          'h' => 24,
        }.each do |unit, count|
          res << Kernel.format('%<n>2d%<unit>s', n: value % count, unit: unit)
          value /= count

          break if value.zero?
        end

        res << "#{value}d" if value.positive?

        res.reverse.join(' ')
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
motoko-1.2.1 lib/motoko/utils/time_ago.rb
motoko-1.2.0 lib/motoko/utils/time_ago.rb
motoko-1.1.0 lib/motoko/utils/time_ago.rb
motoko-1.0.0 lib/motoko/utils/time_ago.rb