Class: Time

Inherits:
Object
  • Object
show all
Defined in:
lib/quandl/operation/core_ext/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.elapsed(message = nil, &block) ⇒ Object



12
13
14
# File 'lib/quandl/operation/core_ext/time.rb', line 12

def elapsed(message = nil, &block)
  log_elapsed(message, &block)
end

.log_elapsed(message = nil, &block) ⇒ Object



3
4
5
6
7
8
9
10
# File 'lib/quandl/operation/core_ext/time.rb', line 3

def log_elapsed(message = nil, &block)
  timer = Time.now
  result = block.call
  message = "#{message} (#{timer.elapsed.microseconds}ms)"
  puts message
  Quandl::Logger.info(message)
  result
end

Instance Method Details

#elapsedObject



52
53
54
# File 'lib/quandl/operation/core_ext/time.rb', line 52

def elapsed
  elapsed_since(Time.now)
end

#elapsed_msObject



60
61
62
# File 'lib/quandl/operation/core_ext/time.rb', line 60

def elapsed_ms
  "#{elapsed.microseconds}ms"
end

#elapsed_since(time) ⇒ Object



56
57
58
# File 'lib/quandl/operation/core_ext/time.rb', line 56

def elapsed_since(time)
  time - self
end

#floor(seconds = 60) ⇒ Object



37
38
39
# File 'lib/quandl/operation/core_ext/time.rb', line 37

def floor(seconds = 60)
  Time.at((to_f / seconds).floor * seconds)
end

#microsecondsObject



41
42
43
# File 'lib/quandl/operation/core_ext/time.rb', line 41

def microseconds
  (to_f * 1000.0).to_i
end

#month_from_beginning_to_endObject



25
26
27
# File 'lib/quandl/operation/core_ext/time.rb', line 25

def month_from_beginning_to_end
  (beginning_of_month..end_of_month)
end

#round(seconds = 60) ⇒ Object



33
34
35
# File 'lib/quandl/operation/core_ext/time.rb', line 33

def round(seconds = 60)
  Time.at((to_f / seconds).round * seconds)
end

#this_month?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/quandl/operation/core_ext/time.rb', line 29

def this_month?
  month_from_beginning_to_end.cover?(Time.now)
end

#this_week?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/quandl/operation/core_ext/time.rb', line 21

def this_week?
  week_from_beginning_to_end.cover?(Time.now)
end

#week_from_beginning_to_endObject



17
18
19
# File 'lib/quandl/operation/core_ext/time.rb', line 17

def week_from_beginning_to_end
  (beginning_of_week..end_of_week)
end