Class: Wavefront::ParseTime

Inherits:
Object
  • Object
show all
Defined in:
lib/wavefront-sdk/parse_time.rb

Overview

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.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(time, in_ms = false) ⇒ ParseTime

param t [Numeric] a timestamp param ms [Bool] whether the timestamp is in milliseconds



13
14
15
16
# File 'lib/wavefront-sdk/parse_time.rb', line 13

def initialize(time, in_ms = false)
  @t = time
  @ms = in_ms
end

Instance Attribute Details

#msObject (readonly)

Returns the value of attribute ms.



8
9
10
# File 'lib/wavefront-sdk/parse_time.rb', line 8

def ms
  @ms
end

#tObject (readonly)

Returns the value of attribute t.



8
9
10
# File 'lib/wavefront-sdk/parse_time.rb', line 8

def t
  @t
end

Instance Method Details

#parse!Object



52
53
54
55
56
57
# File 'lib/wavefront-sdk/parse_time.rb', line 52

def parse!
  method = ('parse_time_' + t.class.name.downcase).to_sym
  send(method)
rescue StandardError
  raise Wavefront::Exception::InvalidTimestamp
end

#parse_time_datetimeObject



48
49
50
# File 'lib/wavefront-sdk/parse_time.rb', line 48

def parse_time_datetime
  parse_time_time
end

#parse_time_fixnumFixnum



20
21
22
# File 'lib/wavefront-sdk/parse_time.rb', line 20

def parse_time_fixnum
  t
end

#parse_time_integerInteger



26
27
28
# File 'lib/wavefront-sdk/parse_time.rb', line 26

def parse_time_integer
  t
end

#parse_time_stringFixnum



32
33
34
35
36
# File 'lib/wavefront-sdk/parse_time.rb', line 32

def parse_time_string
  return t.to_i if t =~ /^\d+$/
  @t = Time.parse("#{t} #{Time.now.getlocal.zone}")
  parse_time_time
end

#parse_time_timeInteger



40
41
42
43
44
45
46
# File 'lib/wavefront-sdk/parse_time.rb', line 40

def parse_time_time
  if ms
    t.to_datetime.strftime('%Q').to_i
  else
    t.strftime('%s').to_i
  end
end