Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support %iso8601 special case for time_format. fix #1528 #1562

Merged
merged 1 commit into from
May 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/fluent/time.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ def initialize(format = nil, localtime = true, timezone = nil)
@parse = case
when format_with_timezone && strptime then ->(v){ Fluent::EventTime.from_time(strptime.exec(v)) }
when format_with_timezone then ->(v){ Fluent::EventTime.from_time(Time.strptime(v, format)) }
when format == '%iso8601' then ->(v){ Fluent::EventTime.from_time(Time.iso8601(v)) }
when strptime then ->(v){ t = strptime.exec(v); Fluent::EventTime.new(t.to_i + offset_diff, t.nsec) }
when format then ->(v){ t = Time.strptime(v, format); Fluent::EventTime.new(t.to_i + offset_diff, t.nsec) }
else ->(v){ Fluent::EventTime.parse(v) }
Expand Down
12 changes: 12 additions & 0 deletions test/test_time_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,18 @@ def test_parse_nsec_with_strptime
assert_equal_event_time(time, parser.parse('28/Feb/2013:12:00:00:123456789 +0900'))
end

def test_parse_iso8601
parser = Fluent::TimeParser.new('%iso8601')

assert(parser.parse('2017-01-01T12:00:00+09:00').is_a?(Fluent::EventTime))

time = event_time('2017-01-01T12:00:00+09:00')
assert_equal(time, parser.parse('2017-01-01T12:00:00+09:00'))

time_with_msec = event_time('2017-01-01T12:00:00.123+09:00')
assert_equal(time_with_msec, parser.parse('2017-01-01T12:00:00.123+09:00'))
end

def test_parse_with_invalid_argument
parser = Fluent::TimeParser.new

Expand Down