Skip to content

Commit

Permalink
Update parsing regexes to handle (ignore) milliseconds
Browse files Browse the repository at this point in the history
- This is a potential fix to the issue brought up in jackc#75
  • Loading branch information
Eli Fatsi committed Apr 7, 2021
1 parent 3ef83ab commit 2dd60de
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/tod/time_of_day.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class TimeOfDay
([0-5]\d)?
:?
([0-5]\d)?
(?:\.\d{3})?
\z
/x

Expand All @@ -24,6 +25,7 @@ class TimeOfDay
([0-5]\d)?
:?
([0-5]\d)?
(?:\.\d{3})?
\s*
([ap])
\.?
Expand Down
14 changes: 14 additions & 0 deletions test/tod/conversion_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,4 +88,18 @@ class <<t

assert_equal(tod, Tod::TimeOfDay.new(24, 00, 00))
end

it "parses 24:00:00.000" do
t = "24:00:00.000"
tod = Tod::TimeOfDay(t)

assert_equal(tod, Tod::TimeOfDay.new(24, 00, 00))
end

it "parses 04:00:00.000 pm" do
t = "04:00:00.000 pm"
tod = Tod::TimeOfDay(t)

assert_equal(tod, Tod::TimeOfDay.new(16, 00, 00))
end
end

0 comments on commit 2dd60de

Please sign in to comment.