Class: Wavefront::ParseTime
- Inherits:
-
Object
- Object
- Wavefront::ParseTime
- 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
-
#ms ⇒ Object
readonly
Returns the value of attribute ms.
-
#t ⇒ Object
readonly
Returns the value of attribute t.
Instance Method Summary collapse
-
#initialize(t, 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(t, ms = false) ⇒ ParseTime
param t [Numeric] a timestamp param ms [Bool] whether the timestamp is in milliseconds
12 13 14 15 |
# File 'lib/wavefront-sdk/parse_time.rb', line 12 def initialize(t, ms = false) @t = t @ms = ms end |
Instance Attribute Details
#ms ⇒ Object (readonly)
Returns the value of attribute ms.
7 8 9 |
# File 'lib/wavefront-sdk/parse_time.rb', line 7 def ms @ms end |
#t ⇒ Object (readonly)
Returns the value of attribute t.
7 8 9 |
# File 'lib/wavefront-sdk/parse_time.rb', line 7 def t @t end |
Instance Method Details
#parse! ⇒ Object
51 52 53 54 55 56 |
# File 'lib/wavefront-sdk/parse_time.rb', line 51 def parse! method = ('parse_time_' + t.class.name).to_sym send(method) rescue raise Wavefront::Exception::InvalidTimestamp end |
#parse_time_DateTime ⇒ Object
47 48 49 |
# File 'lib/wavefront-sdk/parse_time.rb', line 47 def parse_time_DateTime parse_time_Time end |
#parse_time_Fixnum ⇒ Fixnum
Returns timestamp.
19 20 21 |
# File 'lib/wavefront-sdk/parse_time.rb', line 19 def parse_time_Fixnum t end |
#parse_time_Integer ⇒ Integer
Returns timestamp.
25 26 27 |
# File 'lib/wavefront-sdk/parse_time.rb', line 25 def parse_time_Integer t end |
#parse_time_String ⇒ Fixnum
Returns timestamp.
31 32 33 34 35 |
# File 'lib/wavefront-sdk/parse_time.rb', line 31 def parse_time_String return t.to_i if t =~ /^\d+$/ @t = DateTime.parse("#{t} #{Time.now.getlocal.zone}") parse_time_Time end |
#parse_time_Time ⇒ Integer
Returns timestamp.
39 40 41 42 43 44 45 |
# File 'lib/wavefront-sdk/parse_time.rb', line 39 def parse_time_Time if ms t.to_datetime.strftime('%Q').to_i else t.strftime('%s').to_i end end |