Sha256: e19dd00625f00b18b30cb7cd5ef90d474aff7c9527f5f996875f5a7b766e3f24

Contents?: true

Size: 682 Bytes

Versions: 1

Compression:

Stored size: 682 Bytes

Contents

module Fluent
  module Tai64nParserMixin
    def try_replace_tai64n(str)
      tai64n, rest = str[0,25], str[25..-1]
      parsed = parse_tai64n(tai64n)
      if parsed
        "#{parsed}#{rest}"
      else
        log.info("tai64n_parser: record['#{key}']='#{str}' does not start with valid tai64n")
        str
      end
    end

    def parse_tai64n(tai64n)
      # @4000000052f88ea32489532c
      # 0123456789012345678901234
      # 0         1         2
      #   |-------------||------|
      return nil unless tai64n[0,2] == '@4'
      ts = tai64n[2,15].hex
      tf = tai64n[17,8].hex
      t = Time.at(ts-10,tf/1000.0)
      t.strftime("%Y-%m-%d %X.%9N")
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
fluent-plugin-tai64n_parser-0.2.0 lib/fluent/plugin/tai64n_parser_mixin.rb