Permalink
Browse files

Merge pull request #307 from kakra/patch-1

Improve German date format parser
  • Loading branch information...
2 parents df691d9 + 0bf4c09 commit 2b1eae7ec440d767c09e0b1a7f0e9bcf30ce1d6c @davispuh davispuh committed Jan 12, 2018
Showing with 4 additions and 1 deletion.
  1. +1 −1 lib/chronic/parser.rb
  2. +3 −0 test/test_parsing.rb
View
@@ -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!(/\./, ':')
View
@@ -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

0 comments on commit 2b1eae7

Please sign in to comment.