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.
28
29
30
31
|
# File 'lib/fluent/time.rb', line 28
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
104
105
106
|
# File 'lib/fluent/time.rb', line 104
def method_missing(name, *args, &block)
@sec.send(name, *args, &block)
end
|
Class Method Details
.eq?(a, b) ⇒ Boolean
87
88
89
90
91
92
93
|
# File 'lib/fluent/time.rb', line 87
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
79
80
81
|
# File 'lib/fluent/time.rb', line 79
def self.from_msgpack_ext(data)
new(*data.unpack('NN'))
end
|
.from_time(time) ⇒ Object
83
84
85
|
# File 'lib/fluent/time.rb', line 83
def self.from_time(time)
Fluent::EventTime.new(time.to_i, time.nsec)
end
|
.now ⇒ Object
95
96
97
|
# File 'lib/fluent/time.rb', line 95
def self.now
from_time(Time.now)
end
|
.parse(*args) ⇒ Object
99
100
101
|
# File 'lib/fluent/time.rb', line 99
def self.parse(*args)
from_time(Time.parse(*args))
end
|
Instance Method Details
#==(other) ⇒ Object
33
34
35
36
37
38
39
|
# File 'lib/fluent/time.rb', line 33
def ==(other)
if other.is_a?(Fluent::EventTime)
@sec == other.sec
else
@sec == other
end
end
|
#coerce(other) ⇒ Object
59
60
61
|
# File 'lib/fluent/time.rb', line 59
def coerce(other)
[other, @sec]
end
|
#nsec ⇒ Object
45
46
47
|
# File 'lib/fluent/time.rb', line 45
def nsec
@nsec
end
|
#sec ⇒ Object
41
42
43
|
# File 'lib/fluent/time.rb', line 41
def sec
@sec
end
|
#to_int ⇒ Object
49
50
51
|
# File 'lib/fluent/time.rb', line 49
def to_int
@sec
end
|
#to_json(*args) ⇒ Object
67
68
69
|
# File 'lib/fluent/time.rb', line 67
def to_json(*args)
@sec.to_s
end
|
#to_msgpack(io = nil) ⇒ Object
71
72
73
|
# File 'lib/fluent/time.rb', line 71
def to_msgpack(io = nil)
@sec.to_msgpack(io)
end
|
#to_msgpack_ext ⇒ Object
75
76
77
|
# File 'lib/fluent/time.rb', line 75
def to_msgpack_ext
[@sec, @nsec].pack('NN')
end
|
#to_r ⇒ Object
54
55
56
|
# File 'lib/fluent/time.rb', line 54
def to_r
Rational(@sec * 1_000_000_000 + @nsec, 1_000_000_000)
end
|
#to_s ⇒ Object
63
64
65
|
# File 'lib/fluent/time.rb', line 63
def to_s
@sec.to_s
end
|