Skip to content

Commit

Permalink
Support date_formats being a string in parse_with_formats() (#523)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gallaecio authored and asadurski committed Sep 17, 2019
1 parent c6fe0fe commit 1b36da4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dateparser/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ def parse_with_formats(date_string, date_formats, settings):
:returns: :class:`datetime.datetime`, dict or None
"""
if isinstance(date_formats, six.string_types):
warn(_DateLocaleParser.DATE_FORMATS_ERROR_MESSAGE, FutureWarning)
date_formats = [date_formats]
period = 'day'
for date_format in date_formats:
try:
Expand Down
9 changes: 9 additions & 0 deletions tests/test_date.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,15 @@ def test_should_use_last_day_of_month_for_dates_without_day(
month=expected_month,
day=get_last_day_of_month(expected_year, expected_month)))

@parameterized.expand([
param(date_string='25-03-14', date_formats='%d-%m-%y', expected_result=datetime(2014, 3, 25)),
])
def test_should_support_a_string_as_date_formats(self, date_string, date_formats, expected_result):
self.when_date_is_parsed_with_formats(date_string, date_formats)
self.then_date_was_parsed()
self.then_parsed_period_is('day')
self.then_parsed_date_is(expected_result)

def given_now(self, year, month, day, **time):
now = datetime(year, month, day, **time)
datetime_mock = Mock(wraps=datetime)
Expand Down

0 comments on commit 1b36da4

Please sign in to comment.