Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 2 additions & 3 deletions lib/csv.rb
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,9 @@ def initialize(message, line_number)
# A Regexp used to find and convert some common DateTime formats.
DateTimeMatcher =
/ \A(?: (\w+,?\s+)?\w+\s+\d{1,2}\s+\d{1,2}:\d{1,2}:\d{1,2},?\s+\d{2,4} |
\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2} |
# ISO-8601
# ISO-8601 and near-ISO (space instead of T) recognized by DateTime.parse
\d{4}-\d{2}-\d{2}
(?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?(?:[+-]\d{2}(?::\d{2})|Z)?)?)?
(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?(?:[+-]\d{2}(?::\d{2})|Z)?)?)?
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this meets a condition mentioned in this comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kou
Can you help me?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thyresias It seems that this approach is the latter approach not the former approach. Is it intentional?

Anyway, could you refer RFC 3339 instead of "near-ISO" for "YYYY-MM-DD hh:mm:ss" format?

This rejects "YYYY-MM-DD\thh:mm:dd" that is accepted without this change. Could you use [T\s] instead of [T ]?

)\z /x

# The encoding used by all converters.
Expand Down
15 changes: 15 additions & 0 deletions test/csv/test_data_converters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,19 @@ def test_builtin_date_time_converter_iso8601_utc
assert_equal(datetime,
CSV::Converters[:date_time][iso8601_string])
end

def test_builtin_date_time_converter_near_iso
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you split this test to multiple tests like existing test_bulitin_date_time_converter_iso8601_* for easy to debug on failure?
If "2018-01-14 22:25" is failed, the rest cases such as "2018-01-14 22:25:19" aren't executed by this style. The results of all cases are helpful to debug.

[ "2018-01-14 22:25",
"2018-01-14 22:25:19",
"2018-01-14 22:25:19.1",
"2018-01-14 22:25:19.1+09:00",
"2018-01-14 22:25:19+09:00",
"2018-01-14 22:25:19Z",
].each do |string|
datetime = DateTime.parse(string)
assert_equal(datetime,
CSV::Converters[:date_time][string])
end
end

Comment thread
kou marked this conversation as resolved.
Outdated
end