class Fluent::NumericTimeFormatter
Public Class Methods
new(type, localtime = nil, timezone = nil)
click to toggle source
# File lib/fluent/time.rb, line 437 def initialize(type, localtime = nil, timezone = nil) @cache1_key = @cache1_time = @cache2_key = @cache2_time = nil if type == :unixtime define_singleton_method(:format, method(:format_unixtime)) define_singleton_method(:call, method(:format_unixtime)) else # :float define_singleton_method(:format, method(:format_float)) define_singleton_method(:call, method(:format_float)) end end
Public Instance Methods
format_float(time)
click to toggle source
# File lib/fluent/time.rb, line 453 def format_float(time) if time.is_a?(Fluent::EventTime) || time.is_a?(Time) # 10.015 secs for 10_000_000 times call on MacBookAir nsec_s = time.nsec.to_s nsec_s = '0' * (9 - nsec_s.size) if nsec_s.size < 9 "#{time.sec}.#{nsec_s}" else # integer (or float?) time.to_f.to_s end end
format_unixtime(time)
click to toggle source
# File lib/fluent/time.rb, line 449 def format_unixtime(time) time.to_i.to_s end