Skip to content

Commit 2b1eae7

Browse files
authored
Merge pull request #307 from kakra/patch-1
Improve German date format parser
2 parents df691d9 + 0bf4c09 commit 2b1eae7

File tree

2 files changed

+4
-1
lines changed

2 files changed

+4
-1
lines changed

lib/chronic/parser.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ def parse(text)
9494
# Returns a new String ready for Chronic to parse.
9595
def pre_normalize(text)
9696
text = text.to_s.downcase
97-
text.gsub!(/\b(\d{2})\.(\d{2})\.(\d{4})\b/, '\3 / \2 / \1')
97+
text.gsub!(/\b(\d{1,2})\.(\d{1,2})\.(\d{4})\b/, '\3 / \2 / \1')
9898
text.gsub!(/\b([ap])\.m\.?/, '\1m')
9999
text.gsub!(/(\s+|:\d{2}|:\d{2}\.\d+)\-(\d{2}:?\d{2})\b/, '\1tzminus\2')
100100
text.gsub!(/\./, ':')

test/test_parsing.rb

+3
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,9 @@ def test_handle_sd_sm_sy
345345
time = parse_now("09.08.2013")
346346
assert_equal Time.local(2013, 8, 9, 12), time
347347

348+
time = parse_now("9.8.2013")
349+
assert_equal Time.local(2013, 8, 9, 12), time
350+
348351
time = parse_now("30-07-2013 21:53:49")
349352
assert_equal Time.local(2013, 7, 30, 21, 53, 49), time
350353
end

0 commit comments

Comments
 (0)