Skip to content

Commit

Permalink
add one month, one digit, one year pattern to strict
Browse files Browse the repository at this point in the history
  • Loading branch information
ecatkins committed Jul 16, 2019
1 parent 38101d9 commit c5b4717
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
4 changes: 3 additions & 1 deletion datefinder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,8 +173,10 @@ def extract_date_strings_inner(self, text, text_start=0, strict=False):
len(digits) == 2
): # 19 February 2013 year 09:10
complete = True
elif (len(years)==1) and (len(digits)==2): #09/06/2018
complete = True

elif (len(years)==1) and (len(digits) ==2): #09/06/2018
elif (len(years)==1) and (len(months)==1) and (len(digits)==1): # '19th day of May, 2015'
complete = True

if not complete:
Expand Down
17 changes: 17 additions & 0 deletions temp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from datefinder import find_dates
import datefinder

dt = datefinder.DateFinder()

# result = find_dates('19th day of May, 2015', strict=True)

# result = find_dates('May 20th 2015', strict=True)

# result = find_dates('May 20 2015', strict=True)

result = dt.extract_date_strings('May 20th 2015', strict=True)
result = dt.extract_date_strings('May 20 2015', strict=True)



print(list(result))
2 changes: 1 addition & 1 deletion tests/test_extract_date_strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_extract_date_strings(date_string, expected_match_date_string):
['the Friday after next Tuesday the 20th', ''], # no matches
['This Tuesday March 2015 in the evening', ''], # no matches
['They said it was on 01-03-2015', 'on 01-03-2015'], # 3 digits strict match
['May 20th 2015 is nowhere near the other date', 'May 20 2015'], # one month two digit match
['May 20 2015 is nowhere near the other date', 'May 20 2015'], # one month two digit match
])
def test_extract_date_strings_with_strict_option(date_string, expected_match_date_string):
"""
Expand Down
5 changes: 4 additions & 1 deletion tests/test_find_dates_strict.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
('June 2018', []),
('09/06/18', datetime(2018, 9, 6)),
('09/06/2018', datetime(2018, 9, 6))
('09/06/2018', datetime(2018, 9, 6)),
('recorded: 03/14/2008', datetime(2008, 3, 14)),
('19th day of May, 2015', datetime(2015, 5, 19)),
('19th day of May', [])
])
def test_find_date_strings_strict(input_text, expected_date):
Expand Down

0 comments on commit c5b4717

Please sign in to comment.