Class: Contrast::Utils::Timer
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
-
#start_ms ⇒ Integer
readonly
The ms of the Time that this instance represents.
Class Method Summary collapse
-
.ms_to_httpdate(time) ⇒ Object
Converts time given in ms format form TS to HttpDate.
-
.now_ms ⇒ Integer
Time, in ms.
-
.time_now ⇒ Object
Return current time in iso8601 format.
Instance Method Summary collapse
-
#initialize(time = Time.now) ⇒ Timer
constructor
Create a wrapper for the current time.
Constructor Details
#initialize(time = Time.now) ⇒ Timer
Create a wrapper for the current time
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_ms ⇒ Integer (readonly)
Returns 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.
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_ms ⇒ Integer
Returns 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 |