Class: Fluent::EventTime
- Inherits:
-
Object
show all
- Defined in:
- lib/fluent/time.rb
Constant Summary
collapse
- TYPE =
0
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(sec, nsec = 0) ⇒ EventTime
Returns a new instance of EventTime.
25
26
27
28
|
# File 'lib/fluent/time.rb', line 25
def initialize(sec, nsec = 0)
@sec = sec
@nsec = nsec
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
TODO: For performance, implement +, -, and so on
101
102
103
|
# File 'lib/fluent/time.rb', line 101
def method_missing(name, *args, &block)
@sec.send(name, *args, &block)
end
|
Class Method Details
.eq?(a, b) ⇒ Boolean
84
85
86
87
88
89
90
|
# File 'lib/fluent/time.rb', line 84
def self.eq?(a, b)
if a.is_a?(Fluent::EventTime) && b.is_a?(Fluent::EventTime)
a.sec == b.sec && a.nsec == b.nsec
else
a == b
end
end
|
.from_msgpack_ext(data) ⇒ Object
76
77
78
|
# File 'lib/fluent/time.rb', line 76
def self.from_msgpack_ext(data)
new(*data.unpack('NN'))
end
|
.from_time(time) ⇒ Object
80
81
82
|
# File 'lib/fluent/time.rb', line 80
def self.from_time(time)
Fluent::EventTime.new(time.to_i, time.nsec)
end
|
.now ⇒ Object
92
93
94
|
# File 'lib/fluent/time.rb', line 92
def self.now
from_time(Time.now)
end
|
.parse(*args) ⇒ Object
96
97
98
|
# File 'lib/fluent/time.rb', line 96
def self.parse(*args)
from_time(Time.parse(*args))
end
|
Instance Method Details
#==(other) ⇒ Object
30
31
32
33
34
35
36
|
# File 'lib/fluent/time.rb', line 30
def ==(other)
if other.is_a?(Fluent::EventTime)
@sec == other.sec
else
@sec == other
end
end
|
#coerce(other) ⇒ Object
56
57
58
|
# File 'lib/fluent/time.rb', line 56
def coerce(other)
[other, @sec]
end
|
#nsec ⇒ Object
42
43
44
|
# File 'lib/fluent/time.rb', line 42
def nsec
@nsec
end
|
#sec ⇒ Object
38
39
40
|
# File 'lib/fluent/time.rb', line 38
def sec
@sec
end
|
#to_int ⇒ Object
46
47
48
|
# File 'lib/fluent/time.rb', line 46
def to_int
@sec
end
|
#to_json(*args) ⇒ Object
64
65
66
|
# File 'lib/fluent/time.rb', line 64
def to_json(*args)
@sec.to_s
end
|
#to_msgpack(io = nil) ⇒ Object
68
69
70
|
# File 'lib/fluent/time.rb', line 68
def to_msgpack(io = nil)
@sec.to_msgpack(io)
end
|
#to_msgpack_ext ⇒ Object
72
73
74
|
# File 'lib/fluent/time.rb', line 72
def to_msgpack_ext
[@sec, @nsec].pack('NN')
end
|
#to_r ⇒ Object
51
52
53
|
# File 'lib/fluent/time.rb', line 51
def to_r
Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000)
end
|
#to_s ⇒ Object
60
61
62
|
# File 'lib/fluent/time.rb', line 60
def to_s
@sec.to_s
end
|