Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion arrow/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class DateTimeParser:
)
_ESCAPE_RE: ClassVar[Pattern[str]] = re.compile(r"\[[^\[\]]*\]")

_ONE_OR_TWO_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d{1,2}")
_ONE_OR_TWO_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"[1-9]\d|\d")
_ONE_OR_TWO_OR_THREE_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d{1,3}")
_ONE_OR_MORE_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d+")
_TWO_DIGIT_RE: ClassVar[Pattern[str]] = re.compile(r"\d{2}")
Expand Down
19 changes: 18 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ def test_YY_and_YYYY_format_list(self):

assert self.parser.parse(
"15/01/2019T04:05:06.789120Z",
["D/M/YYThh:mm:ss.SZ", "D/M/YYYYThh:mm:ss.SZ"],
["D/MM/YYThh:mm:ss.SZ", "D/MM/YYYYThh:mm:ss.SZ"],
) == datetime(2019, 1, 15, 4, 5, 6, 789120, tzinfo=tz.tzutc())

# regression test for issue #447
Expand Down Expand Up @@ -790,6 +790,23 @@ def test_parse_normalize_whitespace(self):
with pytest.raises(ParserError):
self.parser.parse(" \n Jun 1\t 2005\n ", "MMM D YYYY")

def test_parse_leading_zero(self):
# Regression tests for issue #1084
with pytest.raises(ParserError):
self.parser.parse("01", "M")

with pytest.raises(ParserError):
self.parser.parse("01", "D")

with pytest.raises(ParserError):
self.parser.parse("01", "H")

with pytest.raises(ParserError):
self.parser.parse("01", "h")

with pytest.raises(ParserError):
self.parser.parse("01", "s")


@pytest.mark.usefixtures("dt_parser_regex")
class TestDateTimeParserRegex:
Expand Down