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



14
15
16
# File 'lib/quandl/operation/core_ext/time.rb', line 14

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

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



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

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



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

def elapsed
  elapsed_since(Time.now)
end

#elapsed_msObject



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

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

#elapsed_since(time) ⇒ Object



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

def elapsed_since(time)
  time - self
end

#floor(seconds = 60) ⇒ Object



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

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

#microsecondsObject



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

def microseconds
  (self.to_f * 1000.0).to_i
end

#month_from_beginning_to_endObject



27
28
29
# File 'lib/quandl/operation/core_ext/time.rb', line 27

def month_from_beginning_to_end
  (self.beginning_of_month .. self.end_of_month)
end

#round(seconds = 60) ⇒ Object



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

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

#this_month?Boolean

Returns:

  • (Boolean)


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

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

#this_week?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/quandl/operation/core_ext/time.rb', line 23

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

#week_from_beginning_to_endObject



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

def week_from_beginning_to_end
  (self.beginning_of_week .. self.end_of_week)
end