Sha256: d3286e19c4df2f89f2956698366629e257e448a26de337f299869249a45c7404

Contents?: true

Size: 1.09 KB

Versions: 1

Compression:

Stored size: 1.09 KB

Contents

# encoding: utf-8
require "logstash/namespace"

# Provide our own Time wrapper for ISO8601 support
# Example:
#   >> LogStash::Time.now.to_iso8601
#   => "2010-10-17 00:25:24.619014-0700"
#
#   >> LogStash::Time.now.utc.to_iso8601
#   => "2010-10-17 07:25:26.788704Z"
module LogStash::Time
  ISO8601_STRFTIME = "%04d-%02d-%02dT%02d:%02d:%02d.%06d%+03d:00".freeze
  def self.now
    return Time.new.utc
  end

  if RUBY_PLATFORM == "java"
    #JODA_ISO8601_PARSER = org.joda.time.format.ISODateTimeFormat.dateTimeParser
    #JODA_ISO8601_PARSER = org.joda.time.format.ISODateTimeFormat.dateTimeParser
    JODA_ISO8601_PARSER = org.joda.time.format.DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ")
    UTC = org.joda.time.DateTimeZone.forID("UTC")
    def self.parse_iso8601(t)
      millis = JODA_ISO8601_PARSER.parseMillis(t)
      return Time.at(millis / 1000, (millis % 1000) * 1000)
    end
  else
    def self.parse_iso8601(t)
      # Warning, ruby's Time.parse is *really* terrible and slow.
      return unless t.is_a?(String)
      return Time.parse(t).gmtime
    end
  end
end # module LogStash::Time

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
logstash-lib-1.3.2 lib/logstash/time_addon.rb