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

Add support for RFC 3339 style time #248

Merged
merged 4 commits into from
Jun 29, 2022
Merged

Add support for RFC 3339 style time #248

merged 4 commits into from
Jun 29, 2022

Conversation

thyresias
Copy link
Contributor

@thyresias thyresias commented Jun 15, 2022

fix #247

ISO 8601 uses "T" for separator of date and time.
RFC 3339 also accepts a space for separator of date and time.

@olleolleolle olleolleolle linked an issue Jun 15, 2022 that may be closed by this pull request
@kou
Copy link
Member

kou commented Jun 20, 2022

@ericgpks Do you want to review this?

@ericgpks
Copy link
Contributor

I would like to try review.

lib/csv.rb Outdated
\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
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
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
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 ]?

@@ -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
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.

* support any whitespace instead of T
* split tests for space, add tests for tab
@thyresias
Copy link
Contributor Author

@kou
I made the changes you requested, I hope it is now ok.
I pushed them, do I need to do something else?
And yes, I chose "the latter approach not the former" because it was simplifying the regexp, and the resulting format was recognized by Datetime.parse not only for the case I reported, but for all cases where a T is replaced by a space. So I thought it was eventually better to do it this way, despite your initial preference.

@@ -103,4 +103,89 @@ def test_builtin_date_time_converter_iso8601_utc
assert_equal(datetime,
CSV::Converters[:date_time][iso8601_string])
end

def test_builtin_date_time_converter_rfc3339_minute
iso8601_string = "2018-01-14 22:25"
Copy link
Member

Choose a reason for hiding this comment

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

Could you use rfc3339_string instead of iso8601_string because this is not ISO 8601 format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done.

@kou kou changed the title simplify DateTimeMatcher regexp, matching patterns recognized by Date… Add support for RFC 3339 style time Jun 29, 2022
@kou kou merged commit 1255d8c into ruby:master Jun 29, 2022
@kou
Copy link
Member

kou commented Jun 29, 2022

Thanks!

peterzhu2118 pushed a commit to Shopify/ruby that referenced this pull request Dec 6, 2022
(ruby/csv#248)

fix ruby/csv#247

ISO 8601 uses "T" for separator of date and time.
RFC 3339 also accepts a space for separator of date and time.

ruby/csv@1255d8c304
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

:date_time converter fails to recognize "YYYY-MM-DD HH:MM"
3 participants