-
Notifications
You must be signed in to change notification settings - Fork 122
Closed
Description
require "csv"
csv = '2022-06-14 18:48'
p CSV.parse(csv, converters: :date_time).first.first #=> "2022-06-14 18:48"
p DateTime.parse(csv) #=> #<DateTime: 2022-06-14T18:48:00+00:00 ((2459745j,67680s,0n),+0s,2299161j)>
There are two ways to solve this, I'm not sure which is the best one:
- make the seconds optional:
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 \d{4}-\d{2}-\d{2} (?:T\d{2}:\d{2}(?::\d{2}(?:\.\d+)?(?:[+-]\d{2}(?::\d{2})|Z)?)?)? )\z /x
- or allow "T" to be replaced by " ":
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 \d{4}-\d{2}-\d{2} (?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?(?:[+-]\d{2}(?::\d{2})|Z)?)?)? )\z /x
Metadata
Metadata
Assignees
Labels
No labels