Class: Wavefront::ParseTime
- Inherits:
-
Object
- Object
- Wavefront::ParseTime
- Defined in:
- lib/wavefront-sdk/support/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
-
#ms ⇒ Object
readonly
Returns the value of attribute ms.
-
#t ⇒ Object
readonly
Returns the value of attribute t.
Instance Method Summary collapse
-
#initialize(time, in_ms = false) ⇒ ParseTime
constructor
param t [Numeric] a timestamp param ms [Bool] whether the timestamp is in milliseconds.
- #parse! ⇒ Object
- #parse_time_datetime ⇒ Object
-
#parse_time_fixnum ⇒ Fixnum
Timestamp.
-
#parse_time_integer ⇒ Integer
Timestamp.
-
#parse_time_string ⇒ Fixnum
Timestamp.
-
#parse_time_time ⇒ Integer
Timestamp.
Constructor Details
#initialize(time, in_ms = false) ⇒ ParseTime
param t [Numeric] a timestamp param ms [Bool] whether the timestamp is in milliseconds
15 16 17 18 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 15 def initialize(time, in_ms = false) @t = time @ms = in_ms end |
Instance Attribute Details
#ms ⇒ Object (readonly)
Returns the value of attribute ms.
10 11 12 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 10 def ms @ms end |
#t ⇒ Object (readonly)
Returns the value of attribute t.
10 11 12 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 10 def t @t end |
Instance Method Details
#parse! ⇒ Object
54 55 56 57 58 59 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 54 def parse! method = ('parse_time_' + t.class.name.downcase).to_sym send(method) rescue StandardError raise Wavefront::Exception::InvalidTimestamp end |
#parse_time_datetime ⇒ Object
50 51 52 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 50 def parse_time_datetime parse_time_time end |
#parse_time_fixnum ⇒ Fixnum
Returns timestamp.
22 23 24 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 22 def parse_time_fixnum t end |
#parse_time_integer ⇒ Integer
Returns timestamp.
28 29 30 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 28 def parse_time_integer t end |
#parse_time_string ⇒ Fixnum
Returns timestamp.
34 35 36 37 38 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 34 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_time ⇒ Integer
Returns timestamp.
42 43 44 45 46 47 48 |
# File 'lib/wavefront-sdk/support/parse_time.rb', line 42 def parse_time_time if ms t.to_datetime.strftime('%Q').to_i else t.strftime('%s').to_i end end |