diff --git a/dateparser/date.py b/dateparser/date.py index 750452ec8..8f57d17f5 100644 --- a/dateparser/date.py +++ b/dateparser/date.py @@ -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: diff --git a/tests/test_date.py b/tests/test_date.py index 2ba0772de..6d08a97a7 100644 --- a/tests/test_date.py +++ b/tests/test_date.py @@ -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)