stronger regex and code-style change

This commit is contained in:
wiibaa 2014-05-11 18:02:10 +02:00 committed by Suyog Rao
parent 95abfdebe8
commit 2e21df8e9e

View file

@ -134,19 +134,13 @@ class LogStash::Filters::Date < LogStash::Filters::Base
parser = lambda { |date| joda_parser.parseMillis(date) }
when "UNIX" # unix epoch
parser = lambda do |date|
if /\d+/ === date || date.is_a?(Numeric)
raise "Invalid UNIX epoch value '#{date}'" unless /^\d+(\.\d+)?$/ === date || date.is_a?(Numeric)
(date.to_f * 1000).to_i
else
raise "Invalid UNIX epoch value '#{date}'"
end
end
when "UNIX_MS" # unix epoch in ms
parser = lambda do |date|
if /\d+/ === date || date.is_a?(Numeric)
raise "Invalid UNIX epoch value '#{date}'" unless /^\d+$/ === date || date.is_a?(Numeric)
date.to_i
else
raise "Invalid UNIX epoch value '#{date}'"
end
end
when "TAI64N" # TAI64 with nanoseconds, -10000 accounts for leap seconds
joda_instant = org.joda.time.Instant.java_class.constructor(Java::long).method(:new_instance)