Class: Time

Inherits:
Object show all
Includes:
Lite::Ruby::DateTimeHelper
Defined in:
lib/lite/ruby/time.rb

Constant Summary collapse

DEFAULT_STAMP =
'datetime_iso'
DEFAULT_UNIT =
'year-month-day hour:minute'
STAMPS =
YAML.load_file(File.expand_path('formats/time_stamps.yml', File.dirname(__FILE__))).merge(
  YAML.load_file(File.expand_path('formats/date_stamps.yml', File.dirname(__FILE__)))
).freeze
UNITS =
YAML.load_file(File.expand_path('formats/time_units.yml', File.dirname(__FILE__))).merge(
  YAML.load_file(File.expand_path('formats/date_units.yml', File.dirname(__FILE__)))
).freeze

Class Method Summary collapse

Methods included from Lite::Ruby::DateTimeHelper

#format, #stamp

Class Method Details

.elapse(verbose: false) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/lite/ruby/time.rb', line 25

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

.monotonicObject



35
36
37
# File 'lib/lite/ruby/time.rb', line 35

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