Class: Contrast::Utils::Timer

Inherits:
Object
  • Object
show all
Defined in:
lib/contrast/utils/timer.rb

Overview

Timer is class that can track state about when an event starts and how long it takes Also contains utility methods to get time values in milliseconds

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = Time.now) ⇒ Timer

Create a wrapper for the current time

Parameters:

  • time (Time) (defaults to: Time.now)


17
18
19
20
21
# File 'lib/contrast/utils/timer.rb', line 17

def initialize time = Time.now
  @start_at = time
  @start_ms = (@start_at.to_f * 1000).to_i
  @events = {}
end

Instance Attribute Details

#start_msInteger (readonly)

Returns the ms of the Time that this instance represents.

Returns:

  • (Integer)

    the ms of the Time that this instance represents



12
13
14
# File 'lib/contrast/utils/timer.rb', line 12

def start_ms
  @start_ms
end

Class Method Details

.ms_to_httpdate(time) ⇒ Object

Converts time given in ms format form TS to HttpDate. Returns time format for If-Modified-Since: <day-name>, <day> <month> <year> <hour>:<minute>:<second> GMT Note: The Time class treats GMT (Greenwich Mean Time) and UTC (Coordinated Universal Time) as equivalent.

Parameters:

  • time (Integer)

    time in ms.



40
41
42
# File 'lib/contrast/utils/timer.rb', line 40

def self.ms_to_httpdate time
  Time.at(time / 1000).httpdate unless time.nil?
end

.now_msInteger

Returns time, in ms.

Returns:

  • (Integer)

    time, in ms



24
25
26
# File 'lib/contrast/utils/timer.rb', line 24

def self.now_ms
  (Time.now.to_f * 1000).to_i
end

.time_nowObject

Return current time in iso8601 format.

@return



31
32
33
# File 'lib/contrast/utils/timer.rb', line 31

def self.time_now
  Time.now.utc.iso8601(2)
end