class Wavefront::ParseTime
Parse various times into integers. This class is not for direct consumption: it's used by the mixins parse_time method, which does all the type sanity stuff.
Attributes
ms[R]
t[R]
Public Class Methods
new(time, in_ms = false)
click to toggle source
param t [Numeric] a timestamp param ms [Bool] whether the timestamp is in milliseconds
# File lib/wavefront-sdk/support/parse_time.rb, line 17 def initialize(time, in_ms = false) @t = time @ms = in_ms end
Public Instance Methods
parse!()
click to toggle source
# File lib/wavefront-sdk/support/parse_time.rb, line 57 def parse! method = ('parse_time_' + t.class.name.downcase).to_sym send(method) rescue StandardError raise Wavefront::Exception::InvalidTimestamp, t end
parse_time_datetime()
click to toggle source
# File lib/wavefront-sdk/support/parse_time.rb, line 53 def parse_time_datetime parse_time_time end
parse_time_fixnum()
click to toggle source
@return [Fixnum] timestamp
# File lib/wavefront-sdk/support/parse_time.rb, line 24 def parse_time_fixnum t end
parse_time_integer()
click to toggle source
@return [Integer] timestamp
# File lib/wavefront-sdk/support/parse_time.rb, line 30 def parse_time_integer t end
parse_time_string()
click to toggle source
@return [Fixnum] timestamp
# File lib/wavefront-sdk/support/parse_time.rb, line 36 def parse_time_string return t.to_i if t.match?(/^\d+$/) @t = Time.parse("#{t} #{Time.now.getlocal.zone}") parse_time_time end
parse_time_time()
click to toggle source
@return [Integer] timestamp
# File lib/wavefront-sdk/support/parse_time.rb, line 45 def parse_time_time if ms t.to_datetime.strftime('%Q').to_i else t.strftime('%s').to_i end end