Skip to content

Commit

Permalink
Merge pull request #307 from kakra/patch-1
Browse files Browse the repository at this point in the history
Improve German date format parser
  • Loading branch information
davispuh authored Jan 12, 2018
2 parents df691d9 + 0bf4c09 commit 2b1eae7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/chronic/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def parse(text)
# Returns a new String ready for Chronic to parse.
def pre_normalize(text)
text = text.to_s.downcase
text.gsub!(/\b(\d{2})\.(\d{2})\.(\d{4})\b/, '\3 / \2 / \1')
text.gsub!(/\b(\d{1,2})\.(\d{1,2})\.(\d{4})\b/, '\3 / \2 / \1')
text.gsub!(/\b([ap])\.m\.?/, '\1m')
text.gsub!(/(\s+|:\d{2}|:\d{2}\.\d+)\-(\d{2}:?\d{2})\b/, '\1tzminus\2')
text.gsub!(/\./, ':')
Expand Down
3 changes: 3 additions & 0 deletions test/test_parsing.rb
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,9 @@ def test_handle_sd_sm_sy
time = parse_now("09.08.2013")
assert_equal Time.local(2013, 8, 9, 12), time

time = parse_now("9.8.2013")
assert_equal Time.local(2013, 8, 9, 12), time

time = parse_now("30-07-2013 21:53:49")
assert_equal Time.local(2013, 7, 30, 21, 53, 49), time
end
Expand Down

0 comments on commit 2b1eae7

Please sign in to comment.