Skip to content

Commit

Permalink
Merge pull request #1562 from fluent/iso8601-time-format
Browse files Browse the repository at this point in the history
Support %iso8601 special case for time_format. fix #1528
  • Loading branch information
repeatedly authored May 12, 2017
2 parents a61bd03 + 9aa238a commit a726cd0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
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

0 comments on commit a726cd0

Please sign in to comment.