Class: ScoutApm::StoreReportingPeriodTimestamp

Inherits:
Object
  • Object
show all
Defined in:
lib/scout_apm/store.rb

Overview

A timestamp, normalized to the beginning of a minute. Used as a hash key to bucket metrics into per-minute groups

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time = Time.now) ⇒ StoreReportingPeriodTimestamp

Returns a new instance of StoreReportingPeriodTimestamp.



154
155
156
157
# File 'lib/scout_apm/store.rb', line 154

def initialize(time=Time.now)
  @raw_time = time.utc # The actual time passed in. Store it so we can to_s it without reparsing a timestamp
  @timestamp = @raw_time.to_i - @raw_time.sec # The normalized time (integer) to compare by
end

Instance Attribute Details

#timestampObject (readonly)

Returns the value of attribute timestamp.



152
153
154
# File 'lib/scout_apm/store.rb', line 152

def timestamp
  @timestamp
end

Class Method Details

.minutes_ago(min, base_time = Time.now) ⇒ Object



159
160
161
162
# File 'lib/scout_apm/store.rb', line 159

def self.minutes_ago(min, base_time=Time.now)
  adjusted = base_time - (min * 60)
  new(adjusted)
end

Instance Method Details

#==(o) ⇒ Object



184
185
186
# File 'lib/scout_apm/store.rb', line 184

def ==(o)
  self.eql?(o)
end

#age_in_secondsObject



192
193
194
# File 'lib/scout_apm/store.rb', line 192

def age_in_seconds
  Time.now.to_i - timestamp
end

#eql?(o) ⇒ Boolean

Returns:

  • (Boolean)


180
181
182
# File 'lib/scout_apm/store.rb', line 180

def eql?(o)
  self.class == o.class && timestamp.eql?(o.timestamp)
end

#hashObject



188
189
190
# File 'lib/scout_apm/store.rb', line 188

def hash
  timestamp.hash
end

#strftime(pattern = nil) ⇒ Object



168
169
170
171
172
173
174
# File 'lib/scout_apm/store.rb', line 168

def strftime(pattern=nil)
  if pattern.nil?
    to_time.iso8601
  else
    to_time.strftime(pattern)
  end
end

#to_sObject



164
165
166
# File 'lib/scout_apm/store.rb', line 164

def to_s
  strftime
end

#to_timeObject



176
177
178
# File 'lib/scout_apm/store.rb', line 176

def to_time
  Time.at(@timestamp)
end