diff --git a/arrow/parser.py b/arrow/parser.py index e4f368ad5..498f42854 100644 --- a/arrow/parser.py +++ b/arrow/parser.py @@ -109,6 +109,14 @@ def parse_iso(self, string): formats = [separator.join(self.MARKERS[:l-i]) for i in range(l) for separator in self.SEPARATORS] + date_string = string + + for separator in self.SEPARATORS: + date_components = date_string.split(separator) + if len(date_components) == 1: + continue + if date_components[len(date_components) - 1] > date_components[0]: + raise ParserError('Could not match input to any of {0} on \'{1}\''.format(formats, string)) if has_time and has_tz: formats = [f + 'Z' for f in formats] diff --git a/tests/parser_tests.py b/tests/parser_tests.py index 7682df8c3..f59086837 100644 --- a/tests/parser_tests.py +++ b/tests/parser_tests.py @@ -236,6 +236,10 @@ def test_parse_subsecond(self): assertEqual(self.parser.parse('2013-01-01 12:30:45.987654', 'YYYY-MM-DD HH:mm:ss.SSSSSS'), expected) assertEqual(self.parser.parse_iso('2013-01-01 12:30:45.987654'), expected) + def test_parse_unsupported_iso(self): + with assertRaises(ParserError): + self.parser.parse_iso('03.04.2017') + def test_parse_subsecond_rounding(self): expected = datetime(2013, 1, 1, 12, 30, 45, 987654) format = 'YYYY-MM-DD HH:mm:ss.S'