Sha256: 6abd142cf29183fac66d45e202eca2605971b7228d8133362951e4615ee8d5ef

Contents?: true

Size: 851 Bytes

Versions: 15

Compression:

Stored size: 851 Bytes

Contents

# frozen_string_literal: true

if Lite::Ruby.configuration.monkey_patches.include?('time')
  class Time

    include Lite::Ruby::DateHelper
    include Lite::Ruby::TimeHelper

    class << self

      def elapse(verbose: false)
        started_at = monotonic
        yield
        ended_at = monotonic
        runtime = ended_at - started_at
        return runtime unless verbose

        { started_at: started_at, ended_at: ended_at, runtime: runtime }
      end

      def monotonic
        Process.clock_gettime(Process::CLOCK_MONOTONIC)
      end

    end

    private

    def default_format
      'year-month-day hour:minute'
    end

    def default_stamp
      :datetime_iso
    end

    def format_for(key)
      TIME_UNITS[key] || DATE_UNITS[key]
    end

    def stamp_for(key)
      TIME_STAMPS[key] || DATE_STAMPS[key]
    end

  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

Version Path
lite-ruby-1.3.3 lib/lite/ruby/time.rb
lite-ruby-1.3.2 lib/lite/ruby/time.rb
lite-ruby-1.3.1 lib/lite/ruby/time.rb
lite-ruby-1.3.0 lib/lite/ruby/time.rb
lite-ruby-1.2.0 lib/lite/ruby/time.rb
lite-ruby-1.1.15 lib/lite/ruby/time.rb
lite-ruby-1.1.14 lib/lite/ruby/time.rb
lite-ruby-1.1.13 lib/lite/ruby/time.rb
lite-ruby-1.1.12 lib/lite/ruby/time.rb
lite-ruby-1.1.11 lib/lite/ruby/time.rb
lite-ruby-1.1.10 lib/lite/ruby/time.rb
lite-ruby-1.1.9 lib/lite/ruby/time.rb
lite-ruby-1.1.8 lib/lite/ruby/time.rb
lite-ruby-1.1.7 lib/lite/ruby/time.rb
lite-ruby-1.1.6 lib/lite/ruby/time.rb