class Fluent::TimeFormatter

Public Class Methods

new(format, localtime, timezone = nil) click to toggle source
# File lib/fluent/mixin.rb, line 21
def initialize(format, localtime, timezone = nil)
  @tc1 = 0
  @tc1_str = nil
  @tc2 = 0
  @tc2_str = nil

  if formatter = Fluent::Timezone.formatter(timezone, format)
    define_singleton_method(:format_nocache) {|time|
      formatter.call(time)
    }
    return
  end

  if format
    if localtime
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).strftime(format)
      }
    else
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).utc.strftime(format)
      }
    end
  else
    if localtime
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).iso8601
      }
    else
      define_singleton_method(:format_nocache) {|time|
        Time.at(time).utc.iso8601
      }
    end
  end
end

Public Instance Methods

format(time) click to toggle source
# File lib/fluent/mixin.rb, line 57
def format(time)
  if @tc1 == time
    return @tc1_str
  elsif @tc2 == time
    return @tc2_str
  else
    str = format_nocache(time)
    if @tc1 < @tc2
      @tc1 = time
      @tc1_str = str
    else
      @tc2 = time
      @tc2_str = str
    end
    return str
  end
end
format_nocache(time) click to toggle source
# File lib/fluent/mixin.rb, line 75
def format_nocache(time)
  # will be overridden in initialize
end