Class: Fluent::NumericTimeFormatter
Instance Method Summary
collapse
#format_nocache, #format_with_subsec, #format_without_subsec
Constructor Details
#initialize(type, localtime = nil, timezone = nil) ⇒ NumericTimeFormatter
437
438
439
440
441
442
443
444
445
446
447
|
# 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
define_singleton_method(:format, method(:format_float))
define_singleton_method(:call, method(:format_float))
end
end
|
Instance Method Details
453
454
455
456
457
458
459
460
461
462
|
# File 'lib/fluent/time.rb', line 453
def format_float(time)
if time.is_a?(Fluent::EventTime) || time.is_a?(Time)
nsec_s = time.nsec.to_s
nsec_s = '0' * (9 - nsec_s.size) if nsec_s.size < 9
"#{time.sec}.#{nsec_s}"
else
time.to_f.to_s
end
end
|
449
450
451
|
# File 'lib/fluent/time.rb', line 449
def format_unixtime(time)
time.to_i.to_s
end
|